Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
sroccaserra opened this issue Jul 6, 2021 · 2 comments
Labels
Bug Help wanted PRs welcome!

Comments

@sroccaserra
Copy link

sroccaserra commented Jul 6, 2021

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

  • when I saved, the editorconfig plugin applied the trim_trailing_whitespace, using a %s/\s\+$//e substitute
  • the subsitute string was changed to '' and not restored
  • the search pattern was restored
  • when I tried to apply g&, it applied s/o// instead of s/o/x

To reproduce the bug

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

[*]
trim_trailing_whitespace = true

Then:

  • open a new file
  • type some text, for example hello world
  • make a subsitution, for example :s/o/x, the text is now hellx world
  • save the file with :w (this also applies the trim_trailing_whitespace rule)
  • repeat the last substitution with & or g& or :s
  • instead of hellx wxrld, the text is hellx wrld: this is a symptom of the bug: the last substitute used is now '' instead of 'x'.

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 sroccaserra changed the title The trim_trailing_whitespace option changes the last substitute string The trim_trailing_whitespace option changes the last substitute string at every file save Jul 20, 2021
@sroccaserra
Copy link
Author

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

@cxw42
Copy link
Member

cxw42 commented Jul 31, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Help wanted PRs welcome!
Projects
None yet
Development

No branches or pull requests

2 participants