Tutorial by Examples

:s/foo/bar Replace the first instance of foo with bar on the current line. :s/foo/bar/g Replace every instance of foo with bar on the current line. :%s/foo/bar/g Replace foo with bar throughout the entire file.
* on the word you want to substitute. :%s//replacement/g, leaving the find pattern empty.
:s/foo/bar/c Marks the first instance of foo on the line and asks for confirmation for substitution with bar :%s/foo/bar/gc Marks consecutively every match of foo in the file and asks for confirmation for substitution with bar
For example, with following nmap: nmap <expr> <S-F6> ':%s/' . @/ . '//gc<LEFT><LEFT><LEFT>' select a word with *, type Shift-F6, type in a replacement and hit Enter to rename all occurrences interactively.

Page 1 of 1