I have an annoying bug regarding intellij 14.0.3. The issue is that it keeps indents on empty lines and I can't remove that whitespace in any way. Under code style, I have not checked the checkbox "keep indents on empty lines" and judging from the display how that functionality works I'd say it would do it.
However, it still keeps the indents and that creates bad diffs in git since whitespace is added. Is this a bug? Can I in any way remove them? I have tried to uncheck that checkbox under both the language I use and the main one. None of them seems to change it.
Try enabling the Strip trailing spaces on save option in Settings/Editor/General.
You can choose whether this should be performed for All lines or only the lines you modify to avoid creating unnecessary diffs.
The whitespace is stripped when you explicitly hit CTRL+S or automatically after some period (IntelliJ has autosaving).
One thing to note is that if you have cursor on an empty line and there are some spaces before it, hitting CTRL + S won't strip the whitespace, because this would probably be annoying as your cursor would jump to the beginning of the line if the file was autosaved by IntelliJ (I read somewhere on YouTrack that this was a design decision).
Here is a screenshot of the option I describe:
What I did to strip spaces without having to open & save each file is running a regex in the find and replace window:
Ctrl+Shift+R
Text to find ^ +\n Find every line that starts with (^) one or more spaces ( +) and nothing else (/n).
Replace with: \n A new line.
General > Regular expression (obviously important to check this box)
Eventually you may want to limit the scope because this will be quite the lengthy operation
Find and eventually continue if IDEA warns for the high amount of occurrences.
Click All Files to run the actual replace operation. It might take some time before IDEA to respond.
Related
There is no easier way to explain what I want to do than a picture:
I would like to reduce the time it takes me to refactor HTML code by deleting all the white space behind (or before, doesn't matter that much) my caret until the next non-blank character, emphasized by the highlighted blue whitespace I would like to delete. I found a way to do this on vim, but I want to do this on Intellij.
Try Ctrl+Alt+J (⌃⇧J on Mac) on the <a>... line to perform the 'Join Lines' action.
More information on the feature can be found here and here.
Am trying to shift multiple lines of code in intellij IDEA by a single space using Tab shortcut but it always shifts by 4 spaces rather than a space. I have tried Edit > Convert Indent > To spaces but to no avail.
How do you shift multiple lines of code by a single space without messing with the default configuration for the file?
As #Andrey already suggested, I would use the Multi Cursor feature that has been around since intellij idea version 13.
I like the Add selection on Next Occurrence feature very much. It helps me to edit multiple lines very fast.
This screenshot shows the action in the Settings -> Keymap screen.
I'm using VB.NET, and my code contains a lot of strings that very often have double quotes inside of them. My problem is that as I'm fixing the string to escape double quotes (replacing every '"' with '""' inside of the string) it messes with the proceeding code, temporarily assuming everything is a string (since the double quotes don't match up) and completely messing up the formatting of other strings. It assumes that the start of a following string is the end of the current string which causes the actual string to be interpreted and formatted as code, which I have to go back and fix (since it adds spaces and other formatting characters that shouldn't actually be there).
Is there any way to disable this behavior? I didn't have the same problem in VS2013. I've been looking under Tools > Options > Text Editor > Basic, but I couldn't find anything relevant.
Additional Information: I can just modify the strings in a separate text document to escape all of the double-quotes (which is what I've resorted to for now), but in VS2013 I could easily just copy/paste the strings directly into my code without it messing up proceeding strings by temporarily interpreting them as code due to the uneven count of double-quotes.
This behavior is especially problematic when manually adding double-quotes within strings, because if you don't escape them quickly enough (or make a brief typo when doing so), you get the same issue.
You might notice that for other languages, such as C++, writing a string on one line (even with an uneven number of double-quotes) does not affect proceeding lines. Having this same behavior for VB would be great, assuming that there's some setting to enable it.
Yes its an inconvenience.
What I usually do is put some non-used character (e.g. some unused symbol on keyboard, or Alt+{some number}) instead of double quotes. When I'm done building my string whatever way I want, I just finalize it with either bringing up the Find and Replace box and replace that character with two double-quotes. Or just put a REPLACE statement immediately following it, replacing that character with Chr(34).
Instead use Chr(34), or if you end up repeating strings at all, store them as a resource.
I am new to Intellij Idea. I didn't find any information on how to wrap the code after certain characters (ex: 150 characters, break the line)
I want to break the code after the vertical line, the following code must come in next line.
Note: I used Reformat code option, but it did just realigned the code with some white spaces etc, but not wrapping up the code. It's difficult to see the end of the code.
You go to Settings (alt+ctrl+s) then select Code Style - General
Here you can configure your margins and if you want the code to wrap after it reaches the end of it
Is there a way to have my line reformatted upon completing it in IntelliJ? (For those familiar, this kind of feature is available on FlashDevelop.)
Let's says I just entered this code in PHP:
$var=array("a","b","c");
Upon entering the semicolon, I would like the editor to reformat it to (or whatever my configuration states):
$var = array("a", "b", "c");
This auto-reformat trigger could also be executed on brackets and other line-terminators characters.
There is no such feature in IDEA. You can use Reformat Code (Ctrl + Alt + L) action when needed.
You can actually do something like.
Go to where you want to insert ;
Tools/Start Macro Recording
Type in ;
Then select Code/Auto Indent Lines
Tools/Stop Macro Recording
Name the macro "reformat"
Now go to settings, Keymap, Macros, select "reformat"
Assign a keyboard shortcut of ;
You may have to play with it a bit to get your cursor in the right spot after the macro runs.
This is based on jhormans answer above and i know that the question is more than 6 years old. But IntelliJ IDEA 2017.1.5 still does not have a feature that automatically reformats the current line when semicolon is pressed like VisualStudios.
The workaround is to create a macro as described by jhorman but after pressing ';' run Code -> Reformat Code. Then stop recording and under Settings/Keymap/Macros add the shortcut "Shift+Comma" to the macro. Now when typing the semicolon by pressing Shift + Comma in the code, the code will be reformated aswell. The only shortcoming: the whole code will be reformated each time Shift+Comma is pressed. This may take a second on large files.
This workaround will only work if you just have one line terminator like semicolon. To automatically reformat the code on multiple line terminators (closing brackets, semicolon, ...) you would need to add the shortcuts to "Settings" -> "Keymap" -> "Main Menu" -> "Code" -> "Reformat Code" directly. In this case there's no need to create a macro.
Just formatting the current line isn't possible as far as i know.