Open sroccaserra opened 3 years ago
This is different (search pattern vs substitution is changed), but might be related to: #94
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:
.
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?