Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 934
Bartosz Bilicki Avatar asked May 16 '16 09:05

Bartosz Bilicki


People also ask

How do you remove the last empty line in Java?

Use str2. trim() or move str2 = str2. replaceAll("\\s","") after the second replaceAll() .

Where is idea properties in IntelliJ?

From the main menu, select Help | Edit Custom Properties. If you do not have any project open, on the Welcome screen, click Configure and then select Edit Custom Properties. If you cannot start IntelliJ IDEA, manually create an empty idea. properties file in the IntelliJ IDEA configuration directory.

Where is the idea properties file?

HOME\idea. properties (where HOME is the user's home directory on the system) IDE_HOME\bin\idea. properties.


2 Answers

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

enter image description here

like image 150
Scolytus Avatar answered Sep 18 '22 20:09

Scolytus


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.

like image 26
Vojtech Ruzicka Avatar answered Sep 18 '22 20:09

Vojtech Ruzicka