17

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.

Bartosz Bilicki
  • 12,599
  • 13
  • 71
  • 113
  • wrap file with #@formatter:off #@formatter:on (http://stackoverflow.com/questions/3375307/how-to-disable-code-formatting-for-some-part-of-the-code-using-comments) – Slava Gornostal Oct 22 '16 at 09:27

2 Answers2

23

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

Scolytus
  • 16,338
  • 6
  • 46
  • 69
9

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.

Bartosz Bilicki
  • 12,599
  • 13
  • 71
  • 113
Vojtech Ruzicka
  • 16,384
  • 15
  • 63
  • 66
  • Thanks! It is indeed work of Save Actions plugin. Disabling 'Activate save actions', or disabling 'reformat file' in save actions settings leaves blank lines in properties files. I tried to exclude properties file from save actions, providing .*/.*\.properties as 'file path exclusions' in save action settings, but this does not work .. – Bartosz Bilicki May 16 '16 at 09:57
  • Tried the exclusion suggested by their hint and does not work for me either. – Vojtech Ruzicka May 16 '16 at 10:04
  • It seems to be bug in plugin indeed (file exclusions are ignored). I have project files in same directory as source code (linked bug is for case when project files are in different directory as source files) but bug still occurs for me and file exclusions are ignored. – Bartosz Bilicki May 16 '16 at 10:20
  • 1
    Update your plugin to version 11 it should work now with multiple modules and the exclusion regex `.*\.properties`, see https://github.com/dubreuia/intellij-plugin-save-actions/issues/29 @BartoszBilicki – Alexandre DuBreuil May 26 '16 at 13:29
  • @Alexandre DuBreuil I confirm that exclusion works in 0.11 version. Thanks! – Bartosz Bilicki May 30 '16 at 13:16