Reputation: 16993
I am having an issue with Pycharm where certain files tracked by git will show up as having been modified when I haven't done anything but visit the file. Usually the modifications are tabs being changed to spaces or vice-versa, or tabs being added to/removed from empty lines. Once this kind of modification is made, I can't seem to roll back the changes no matter what I do. I have "keep indents on empty lines" set everywhere it can be set in settings, but Pycharm will still remove indents on some empty lines, and even when I re-add them or revert local changes to the document, as soon as I navigate away from the file it will show as modified again, and the tabs have once again been removed...I assume this is something that I am doing unknowingly, or a setting that I have set rather than a bug in Pycharm, but it is driving me crazy! Any ideas how to solve this issue?
Upvotes: 2
Views: 2847
Reputation: 1022
To keep PyCharm from removing whitespace, do this:
Change INDENT_TO_CARET_ON_PASTE to false in editor.xml if it exists, that worked for me ...
<application>
<component name="CodeInsightSettings">
<option name="REFORMAT_ON_PASTE" value="1" />
<option name="INDENT_TO_CARET_ON_PASTE" value="false" />
</component>
<component name="EditorSettings">
<option name="IS_VIRTUAL_SPACE" value="true" />
<option name="STRIP_TRAILING_SPACES" value="None" />
</component>
</application>
Fixed: PyCharm was destroying vertical alignment readability I spent so much time to achieve and it was driving me mad, scrunched code is inefficient. v2020.2.5
To find that file: https://www.jetbrains.com/help/idea/tuning-the-ide.html#config-directory
Or rename the file and restart. On changing a setting, it will be recreated with only that new change that was made. (Note my settings file might have been from a much earlier version long ago, now upgraded.)
Where is the checkbox for that in the gui? File > Settings ... ? ... INDENT_TO_CARET_ON_PASTE
Upvotes: 0
Reputation: 17867
There are two more settings you might want to check:
Preferences > Editor > General > Other > Strip trailing spaces on Save
Preferences > Editor > Code style > Python > Tabs and Spaces > Use tab character
Upvotes: 3