Friday, November 25, 2011

Re: undo lust substitution made with :%s/foo/bar/gc

On 11/25/11 15:54, denis perelyubskiy wrote:
> Hello,
>
> Is there a quick way to undo only the very last substitution made
> while performing '%s/foo/bar/gc' *while in the substitution mode*. I
> think I am asking whether there is something I can do at "replace with
> le (y/n/a/q/l/^E/^Y)?' prompt to go back one substitution.
>
> Use-case is something like: I go through the file, only making a
> couple of changes (but skipping many-many matches). I then screw one
> up. I either need to go back and make all those changes again, or -
> ideally - press something to undo my decision on the last prompt.
> Preferably it'd be the latter.

Not that I know of, but I've done this and my remedy is usually
the following:

:%s/foo/bar/gc
(answer some y/n and screw one up)
q (quit the substitute)
u (undo the biffup)
:+,$s//~/&
(restart the previous command from the next line
searching for the same thing, replacing with the
same replacement, using the same flags)

which you can read about at

:help s~
:help :s_flags

If you've specified an original range of "%", then the above
works. Otherwise, you'd have to tweak the starting/ending range
on the 2nd/restarting command.

-tim


--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments: