<pattern>is a Regex
|&||Keep the flags from the previous substitute.|
|c||Prompt to confirm each substitution.|
|e||Do not report errors.|
|g||Replace all occurrences in the line.|
|n||Report the number of matches, do not actually substitute.|
set gdefault to avoid having to specify the 'g' flag on every substitute.
gdefault is set, running
:s/foo/bar on the line
foo baz foo will yield
bar baz bar instead of
bar baz foo.
Keyboard short-cut to replace currenlty highlighted word
For example, with following
select a word with *, type Shift-F6, type in a replacement and hit Enter to rename all occurrences interactively.
Quickly refactor the word under the cursor
* on the word you want to substitute.
:%s//replacement/g, leaving the find pattern empty.
Replacement with interactive approval
: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
: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.