dhruv's wiki



Substitution Flags

" the 'n' flag is handy if you need to do a dry run before actually
" substituting
:s/old/new/gn  " n returns the number of substitution that will be made
:%&g           " Repeat (on entire file) last substitution without flags, ie,
               " will replace 'old' with 'new'
:s/old/new/gc  " ask for confirmation

More on repeat last substitution here.

Substitute only in visual block

" first make visual selection
" then :s
" which will expand to :'<,'>
" replace text in visual block using \%V

Substitute from current line till end of file

" $ corresponds to end of file

Substitute from specific line till end of file

" from line 2 till end of file

Don't error out if missing


Search with contents of register 0

:%s/<c-r>0/text to replace with/g

Replace with contents of register 0

:%s/text to search/\=@0/g