editorconfig / editorconfig-vim

EditorConfig plugin for Vim
http://editorconfig.org
Other
3.13k stars 137 forks source link

The trim_trailing_whitespace option changes the last substitute string at every file save #175

Open sroccaserra opened 3 years ago

sroccaserra commented 3 years ago

What I experienced

While editing a file, I started to do some substitutions with :s/o/x. I tested it on one line, saved the file, and tried to apply it to the whole file with g&.

What I expected: all "o" chars changing to "x" chars in the file. What happened: all the "o" chars of the file disapeared.

I had the editorconfig active, with the trim_trailing_whitespace active.

What I suppose

To reproduce the bug

In an empty directory, add this simple .editorconfig file:

[*]
trim_trailing_whitespace = true

Then:

What I tried & explored

I saw in the code that the view is saved and restored by s:TrimTrailingWhitespace(), apparently this does not restore the substitute string.

According to this documentation, The last used search pattern and the redo command "." will not be changed by the function

So maybe this is a Vim limitation, unlike the search pattern, the subsitute string is changed by the function and not restored?

sroccaserra commented 3 years ago

This is different (search pattern vs substitution is changed), but might be related to: #94

cxw42 commented 3 years ago

Thanks very much for reporting!

I can reproduce if the "open a new file" step in your original post is vim bar.txt. However, if I just say vim and then :w foo.txt, the issue does not appear: image.
That might be yet another issue :) .

I agree this behaviour should be changed if possible, to avoid surprising the user.