You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
Using :@: (execute last command) seems to work as I expect, it replaces "o" chars by "x" chars in my example
Commenting the trim_trailing_whitespace rule removes the bug
So maybe this is a Vim limitation, unlike the search pattern, the subsitute string is changed by the function and not restored?
The text was updated successfully, but these errors were encountered:
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
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: .
That might be yet another issue :) .
I agree this behaviour should be changed if possible, to avoid surprising the user.
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 withg&
.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
trim_trailing_whitespace
, using a%s/\s\+$//e
substituteg&
, it applieds/o//
instead ofs/o/x
To reproduce the bug
In an empty directory, add this simple
.editorconfig
file:Then:
hello world
:s/o/x
, the text is nowhellx world
:w
(this also applies thetrim_trailing_whitespace
rule)&
org&
or:s
hellx wxrld
, the text ishellx wrld
: this is a symptom of the bug: the last substitute used is now '' instead of 'x'.What I tried & explored
:@:
(execute last command) seems to work as I expect, it replaces "o" chars by "x" chars in my exampletrim_trailing_whitespace
rule removes the bugI 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?
The text was updated successfully, but these errors were encountered: