How to stop IntelliJ IDEA from removing empty lines from .properties files? - intellij-idea

How to stop IntelliJ IDEA from removing empty lines from .properties files?
I want to use empty lines to separate sections of files (database properties, RabbitMQ properties, business properties, etc).
When file is saved, empty lines are removed.
I have IntelliJ IDEA 2016.1.2, with 'Save actions' and 'Properties' plugins.
I see no option to controll empty lines in .properties files anywhere.

This is a bug in 2016.1 and 2016.2:
IntelliJ Bug IDEA-157903
This will be fixed in 2016.3, you can try the IntelliJ EAP
As a workaround, I defined Shift + Ctrl + s to be the Save All, so when I notice that IntelliJ delets my blank lines, I issue an undo and use the shortcut with Shift to save the file without reformating.
Update November 2016: I can confirm that a option to keep blank lines in property files was added in version 2016.3

IntelliJ does that when you run Reformat Code action.
It can be disabled by disabling "Formatting actions -> Reformat file" in the Save Actions plugin settings. However, by doing this all your files are of course not being reformatted upon save.
There is blank lines settings for java code in Settings -> Editor -> Java -> Blank lines, but unfortunately not for property files as far as I know.
Better way to prevent reformatting would be just to add property file exclusion using the following regex
.*/.*\.properties
However, there seems to be issue currently which ignores this settings in some cases
https://github.com/dubreuia/intellij-plugin-save-actions/issues/29
Edit: issue is resolved in 0.11 version of the plugin. Exclusion regex works properly.

Related

PhpStorm AutoComplete code is not working

I'm using PhpStorm over 3 months and it's a good IDE. I do not know what I've clicked yesterday but since yesterday I have issue with code completion in CSS mainly.
On the screen I have VS Code and PhpStorm and also I've opened the same project.
In VS Code it works perfectly. In PhpStorm it doesn't. I tried some Google First Aid like clear cache, update the IDE, turn On/Off Safe mode etc. but nothing changed.
My Code Completion settings:
Based on your PhpStorm editor area screenshot (many thanks for that BTW: not many people do post it even if asked), all your CSS files are treated as a Plain Text. It's rather unlikely to be a glitch, more like accidental settings change.
Settings/Preferences | Plugins -- make sure that CSS plugin is enabled. If not -- enable and restart the IDE.
If still the same: Settings/Preferences | Editor | File Types -- locate "Cascading style sheet" entry and make sure that it has *.css pattern there.
If not there -- it's possible that you have somehow reassigned it to "Text" file type. If it's there -- just add *.css to Cascading style sheet patterns (it will remove it from Text when doing that).
If still nothing: you would need to provide more/new screenshots.

How do I prevent PhpStorm from moving cursor to the left when I press Ctrl+S for save file? [duplicate]

I just updated to PhpStorm 2016 and I noticed that suddenly every time I press Ctrl + S to save the file it removes the spaces/tabs that I pressed to continue writing after testing this bit of code.
Pleas help, this is very annoying for me, since I save my file after every line of code.
Here is a screenshot when I'm about to save, so after hitting Ctrl + S the text cursor will move all the way to the left, deleting all spaces & tabs.
You need to disable Settings/Preferences | Editor | General | Remove trailing spaces on: option.
(NOTE: in older IDE versions you may have just a drop down box and have to select the None option there)
P.S. Please note that if you have .editorconfig files in your project then corresponding setting from there (trim_trailing_whitespace) will overwrite such IDE setting. It is expected as it's the whole nature of such files.
If you do not like that then either edit your .editorconfig file accordingly (https://github.com/editorconfig/editorconfig/wiki/EditorConfig-Properties#current-universal-properties) or disable such support in the IDE (Settings/Preferences | Editor | Code Style | Enable EditorConfig support)
I recently experienced the behavior that trailing spaces got removed everywhere although the option Settings/Preferences > Editor > General > Strip trailing spaces on Save was set to Modified Lines. Setting the option to None didn't help nigher.
The reason for that was, that I had installed the JetBrains IDE plugin EditorConfig. In the root of my (PHP-) project I had a
.editorconfig file with the setting trim_trailing_whitespace = true. Setting that to false, fixed the issue.
PhpStorm 2021.2.3
Just Settings/Preferences > Editor > General
scroll down to On Save

IntelliJ keeps folding my code by default

When I open up any code file .java or .html IntelliJ (12.x) keeps the code folded and I always have to expand everything.
How do I make code expand by default?
In the preferences (ctrl+alt+s on my machine), under Editor, you will find an entry called Code Folding. In there you can choose what's folded by default. In your case, you'll probably want to remove all the defaults.

IntelliJ - not asking if I want to save a file

I'm new to the IntelliJ IDE. In the past I was working with Visual Studio or Eclipse.
In those IDEs there was an asterisk * above the name of the file which has been modified.
But in IntelliJ with the default configuration I can't see if the file is modified. What's more the file is saved automatically when I change focus to another window.
I've found some options under Settings -> IDE Settings -> General -> Synchronization:
Synchronize files on frame activation
Save files on frame deactivation
Save files automatically if application is idle for...
After unchecking all that options the file is not saved automatically every time I change focus to another window, which is good. But still I can't:
see if the file is modified (no asterisk)
decide if the file should be saved when I'm closing it (IDE doesn't ask for that)
And when I'm closing IntelliJ file which has been modified is saved without even noticing.
Do you know what can I do to change how IntelliJ behaves?
After unchecking mentioned options go to:
Settings/Editor(IDE Settings)/Editor Tabs:
Check "Mark modified tabs with asterisk"
On 2019.3 Ultimate it's under:
Settings/Editor/General/Editor Tabs:
Mark modified (*)
The exact Save feature like eclipse is not available in IntelliJ.
Because IntelliJ IDEA has the ability to change so many files
simultaneously in large refactoring actions, and change them without
ever opening them, single file saves don't make very much sense. In
recognition of this, IntelliJ IDEA reserves the right to save any of
your files literally whenever it wishes. It's actually quite nice to
never have to worry about your file's save statuses, once you get used
to it.
"What if I don't like some changes I made, and want to roll them
back?", I hear you say. Well, for that IntelliJ IDEA includes this
amazing feature called the Local History. Every time it saves your
files, IntelliJ IDEA actually saves a diff of your file from it's
previous state, and saves that as well. You can see the entire edit
history of your files (going back some number of days), see the
changes you've made, and roll back any change. It rules triumphantly,
and more than makes up for the temporary disorientation caused by lack
of single-file save.
https://intellij-support.jetbrains.com/hc/en-us/community/posts/206336279/comments/207351939
To show an asterisk when a file is modified: open Settings (CTRL+ALT+S), switch to Editor > General > Editor Tabs and select the Mark modified tab with asterisk checkbox.
To remove autosave, uncheck: Appearance & Behavior > System Settings > Save files on frame deactivation

Disable reformatting code when saving files

I made a small change to an old java file in IntelliJ and when I save the file the IDE automatically reformats all the code. Normally this would be preferable, however it seems almost every line has unnecessary white space that gets cleaned up. Now it appears the entire file was modified even though I only made a small fix. This will make looking at the significant changes in VCS more difficult.
Is there a way to disable code reformatting when a file gets saved? So far I haven't had any luck finding the setting in the Project Settings dialog. I'm using IntelliJ IDEA 9.0.2
Alternatively I could perform the reformat, commit the changes, and then make my modification but I feel that this will end up happening a lot and I don't want to impose my formatting preferences on code owned by other groups.
Settings | Editor | General > Other | Strip trailing spaces on Save -> None.
Updated for IntelliJ Idea 2021+
Settings | Editor | General > On Save | Remove trailing spaces on: <...> -> None.
For newer versions (at least WebStorm 2018), Ctrl + S is bound to a save Macro that has a reformat code action followed by save.
You can remove this reformat with Ctrl + Shift + A search for Macro then modify the save one.
Edit | Macros | Edit Macros | save | - on the Action: Reformat...
You can add these comments to make it temporarily disable formatting on the file, or a specific function:
// #formatter:off
If you want one section to remain, you can also add this:
// #formatter:on
IntelliJ Documentation Link
If #formatter:off is not working, you can enable it in preferences:
Today in 2020 IDEA is silently formatting HTML before commit, which might break your web pages appearance. To disable that unselect this checkbox:
Preferences -> Tools -> Actions on save -> uncheck "Reformat Code"
Settings > Tools > Actions on save > first line with checkbox "Reformat code"
change "Whole file" to "Changed lines"
As it advertise only the modified lines will be affected by formatting on save.