Intellij: add space after double slashes in line comment - intellij-idea

Is there a way in Intellij IDEA (I'm using version 13) to automatically add a space to line comments between the two slashes and the text:
If I enter :
//This is a comment
I'd like to get the following when I run a code reformat (Ctrl-Alt-L on Windows)
// This is a comment
It's for Javascript files but should be working for other file types.

If you press CTRL / or CMD / it will put // at the beginning of the line and the comment will be properly indented.
// comment with two indents
For this to work Comment at first column must be checked in Editor->CodeStyle->Javascript->Wrapping and Braces->Keep when reformatting like mentioned in another answer.
This screenshot is for Java, but it works the same for Javascript. Just choose javascript in the menu
If you want to write multiline comment you can use CTRL SHIFT / or CMD SHIFT / That way when you go into new line, you will have one space after the comment start
/*
* there is space before this*/

Related

How to shorten the first line in the Intellij console?

I want my first line at the top of the console to look like this:
, but mine looks like this, and it's long:
How can I shorten it to like the first picture?
I'm watching Java tutorials on youtube and their first lines ("C:\programs Files\Java\jdk\whatever"...) are always so short and pretty with 3 cute dots in the end, but mine is long and annoying.
You can define the lines which should be folded:
Right click on that line in the console
Choose "Fold Lines Like This"
Click OK
You can also define special keywords/phrases in this menu, where lines, which contains the phrase will be folded with ellipsis (...) at the end.
See the ConsoleViewImpl.java file in the source code of IntelliJ IDEA
This line (execution command) will be automatically hidden in case the string length is more than 1000 symbols.
So, once you add something to the execution command (for example by adding libraries), the execution command is folded automatically.

Intellij: how to convert indents for all files

I know how to convert indent for a single file. I go to edit -> convert indent -> space/tab.
But I want to do this for all files under a directory.
I try click on a directory and then go to edit -> convert indent, but the options are grayed out.
You can use the shortcut Ctrl+ALT+L (Windows/Linux) or ⌥⌘+L (MAC OS X) and select the Rearrange entries option to reformat the code in the current file or reformat a module or directory.
You can also Right-click a module, file, or directory from the context menu and select Reformat Code and also select the Rearrange entries option.
This will convert the indents for all files/directories selected:
This works on most of the Jetbrains IDES (iDea, PyCharm, WebStorm, RubyMine, and so on.)
It seems there is no such dedicated option in IntelliJ, but you could just work around it using a "low-level" Replace All action.
Open the Edit → Find → Replace in Files... dialog
In case you want to convert spaces to tabs, you should
Enter in the Find field (i.e. four spaces (or whatever number of spaces the project is currently indented with))
Press the Regex search modifier (Alt + X)
Enter \t in the Replace field
NB: In case you have valid strings with 4+ spaces in them, they will get replaced too. In most use cases, however, this is not happening.
In case you want to convert tabs to spaces, you should do the same as above, but swap the Find and Replace field contents
NB: Again, if you have valid strings with tabs in them, they will get replaced too. I haven't had this use case, because I've only needed to convert in the opposite direction.
You will probably also want to set a File mask in order not to replace spaces in code-irrelevant files

How do you get Notepad++ to treat # (hashtag) like a comment?

I have an SQL export file from my server with comments. The line comment operator used was the hashtag #. Notepad++ does not treat this like a commented out line, as in, the color does not change and any words such as like and while are changed to bold blue.
When you run the script on the server to install the SQL, it runs fine, the comments are treated as they should be. How do you tell NPP that the # operator is supposed to comment out the line? Both show the color and have Ctrl-k add a # in front of the line.
Note: I added commentLine="#" in the langs.xml file with no luck.
View -> User defined Dialogue -> Comment & number -> Comment Line
There you type in "#"
Before this you need to define a new language in the upper buttons.
What means, that the whole rest of the syntax isn't highlighted anymore.
But you could define it that way, how you want to. So you have an individual Syntax Highlighting including the commenting via "#"

Intellij - Reformat Code - Insert whitespace between // and the comment-text?

I am working with another human being on project from that the professor expects to have uniform code-style. We have written large separate junks of code on our own, in which one has written single line comments without a white-space between the single-line-comment-token and the other one has inserted a white-space. We are working with IntelliJ and have failed to find an option to enable the Reformat Code function, to insert a white-space.
TLDR:
Can you tell us how to convert comments from that to this in IntelliJ?
// This is a load bearing comment - don't dare to remove it
//This is a load bearing comment - don't dare to remove it!
You can do a global search and replace (ctrl-shift-r on windows with default keyboard layout, or Replace in Path under the Edit/Find menu).
Check the regular expression option and enter //(\S.*) as the text to find and // $1 as the replacement. Check the whole project option, and clear any file masks. You can single step through the replacements, or simply hit the All Files option.

How can I configure removing space between line comment slasles and text in Intellij IDEA?

If I want to comment line I use "Ctrl+/" and get the "//" at start of line
Then I use auto formatting with "Ctrl+alt+L" keys and get
At the end I must remove space between "//" and text manually every time...
Can I do all of these steps in one time? I didn't find any settings for this...
An alternative, not perfect though, is:
Editor -> Code Style -> Java -> Code Generation
Uncheck Line Comment at first column
The menu hierarchy is the one in Intellij IDEA 14.
I suggest you can use a setting to avoid the further indentation of your comment (the effect of the second screenshot).
Your comments will look like this:
// Bundle b = new Bundle();
That might not be quite exactly what you want, but at least you will be able to use "Ctrl+/" after the reformatting to return the line to a properly aligned state.
Here is the setting:
Go to Settings -> Project Settings -> Code Style -> Java
On the Wrapping and Braces tab, find the tree item at the top: Keep when reformatting and tick: Comment at first column
This works for Scala.
Preferences -> Editor -> Code Style -> Scala -> Other -> Comment Code
Uncheck Line comment at first column and Block comment at first column.
Example:
def regexTest(): Unit = {
Comment
When press comment shortcut in line 2, the above code becomes
def regexTest(): Unit = {
//Comment
Version 2020.2