Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stop intellij-idea from removing white spaces at end of text lines in my file?

I am using 2018.1.5 community edition of intellij editor to edit a plain text file.

I am not using a project. I start it, on Linux as follows:

  idea.sh  my_file.mpl

where my_file.mpl is plain text file.

And this works well, except for one big problem.

I need to have an empty space at end of some lines. i.e. after the line character on some line in the file, I insert some white. I see the space is there, by doing View->Active editor->Show White spaces. I can see the small tiny dotts, showing there are white space character at end of line.

But as soon as I save the file, these white spaces are removed from end of line.

This causes a problem for me (for other reason, when this file is read by another app).

Is there an option to tell it intellij NOT to remove white spaces after the last character on the line?

like image 277
Nasser Avatar asked Jul 25 '18 21:07

Nasser


3 Answers

Go to File->Settings->Editor->General and under Other, set the drop down next to Strip trailing spaces on Save to whatever you wish. For future reference, you can press Ctrl-Shift-A and type a search term to find any menu command or setting very quickly. In this case, "trailing spaces" or "strip trailing spaces" works really well.

like image 106
Code-Apprentice Avatar answered Oct 25 '22 03:10

Code-Apprentice


Newer PyCharm (2020 and beyond) have slightly different answer than Code-Apprentice's.

Go to File->Settings->Editor->General, and then scroll down to Save Files section. The drop down Strip trailing spaces on Save for: is there. You can select None if you don't want any stripping in no circumstances.

Here is an image showing the setting: Image describing the location of the drop-down

like image 24
Michael Veksler Avatar answered Oct 25 '22 03:10

Michael Veksler


If changing the settings in "Editor > General > Save Files" doesn't work, the below might be useful...

There is a discussion here about a possible bug (or at least confusing scenario) where you have set "Strip trailing spaces on Save for"=None and you still get stripping of trailing spaces, as I did. The comment by Oksana Chumak worked for me - namely, I unticked "Enable EditorConfig Support" in Settings > Editor > Code Style. This seems to allow a config file ".editorconfig" to be used which overrides some settings - also see Andriy Bazanov's answer, quoted below...

NOTE: If you have .editorconfig file in your project, such option can also be controlled via that file. This file can provide more granular control over what files are affected by those settings.

Settings from .editorconfig file will OVERWRITE IDE settings (the whole nature of such files), so if you have such files in your project and such instruction there, you will have to either disable the EditorConfig for this project or disable plugin completely (if you do not care about it at all).

like image 30
Brian O Carroll Avatar answered Oct 25 '22 05:10

Brian O Carroll