Wikia

Vim Tips Wiki

Verbose replace without 'c' flag

Talk0
1,610pages on
this wiki
Revision as of 08:13, October 21, 2012 by Marcin Szamotulski (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Some times I want to replace something in a file, and see if my pattern did not match things I don't want to replace. The vim solution is to use 'c' flag for the substitute command, though sometimes I don't want to go through every substitution. Here is my simple solution, which prints every line which matches the pattern, then makes the substitution, and then prints it again, so you can compare if the changes are ok.

Solution

The solution is to use the global command:

:g/PAT/#|s/PAT/REP/g|#


Comments

Replace

Advertisement | Your ad here

Around Wikia's network

Random Wiki