Wikia

Vim Tips Wiki

Verbose replace without 'c' flag

Talk0
1,599pages on
this wiki

Recently created tip

We have not yet decided whether to keep this tip as its own page or merge it somewhere else. If you have a suggestion on the tip content, please edit this page or add your comments below (do not use the discussion page).

Please discuss whether to keep this as a new tip, or whether to merge it into an existing tip, on the new tips discussion page.
created October 21, 2012 · complexity basic · author Marcin Szamotulski · version 7.0

Sometimes 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.

SolutionEdit

The solution is to use the global command:

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

CommentsEdit

Advertisement | Your ad here

Photos

Add a Photo
103photos on this wiki
See all photos >

Recent Wiki Activity

See more >

Around Wikia's network

Random Wiki