Stop editor from removing spaces while editing

I think the issue is related to some code-style changes that the IDE does on-the-fly, but I cannot find the setting for that:

 

When I type a space/tab and then pause for a moment, the IDE trims the whitespace of the line that I'm editing. As a result, the next character is in the wrong position.

Here's a short demonstration of that. Note that I do not use Backspace. It's the IDE that removes whitespace and moves the cursor:

 

Here are the Editor/General settings, that I think are relevant. I set the "delete trailing spaces on caret line" to false, which should prevent this exact behavior in my understanding:

I have disabled the "EditorConfig" plugin, so there's no config file interfering with anything. 

How can I stop that? I do not want to format the line that I'm currently editing. It's okay to format it on save, but not while editing.

0
8 comments

Hi there,

Yes, that setting + .editorconfig (as a settings source) are the ones that will normally responsible for such "whitespace removal".

 

Please enable "Settings/Preferences | Editor | General | Editor Tabs | Mark modified (*)" option if it's not enabled already.

Now try your editing and see if that asterisk symbol will disappear from the Editor tab once such "white space removal" will happen.

If that's the case, then something saves your file. Could be some File Watcher, or Live Edit functionality (less likely) .. or perhaps it's some CodeSniffer / fixer or alike related functionality.

Please also disable all custom (not bundled by default) plugins. Make sure to restart IDE after disabling plugins.

1

Thanks for the quick response, Andriy!

I found the problem: I've set up a File Watcher to apply coding standards to the PHP file I'm editing.

It seems the file watcher executes almost immediately - I thought that it will only trigger on filesystem changes (not changes in the editor)

→ Any ideas on how to configure the watcher to only run on save/filesystem change?

 

Here's the relevant watcher configuration:

0

Okay, I've found it. As obvious as it now seems, it kept me busy for a few hours:

 

In all File Watchers UNCHECK "Auto-save edited files to trigger the watcher". For obvious reasons :)

0

Yes, you need to uncheck that option. In such case File Watcher will be run on actual file save ("persistent modification") only.

0

I had this happen to me while using RubyMine, it was only happening in .slim files and I eventually figured out it was being caused by the way I was adding the magic string, I had it at the top of the file like this: -#frozen_string_literal: true, I have no idea why it would cause this behaviour, but adding whitespace around the # seemed to have fixed the issue. 

- # frozen_string_literal: true

So simple, yet I spent countless hours trying to figure this one out. Hopefully this can help someone figure out why it is happening in their instance.

0

I am having the same problem on typescript files. I have disabled all linters, and attempted to remove all .editorconfig files recursively. I don't have the file watcher extension, nor the - `frozen` string at the top of my file.

 

0

The exact above problem is happening for me. No luck trying any method so far.

0

Had the same issue on saving my files.

If unchecking “Remove trailing spaces” on Settings > Editor > General > On Save doesn't work (like me), I suggest you check your .editorconfig that in fact overrides this config.

Had to add this to the .editorconfig file

[*.ts]
trim_trailing_whitespace = false
0

Please sign in to leave a comment.