A quick replace in Vim

Cameron Fowler
Sometimes you just don’t want to type what you are trying to replace. In Vim, if you have set incsearch set in your .vimrc you can use ctrl-lto autocomplete the next character of your search.
Combine this with another feature, where if you do a substitution with a blank regular expression, Vim will use your last search term. What does this look like? Well, a fast and effortless replacement:

To recap:
-
Set incremental search in your
~/.vimrc
by addingset incsearch
. -
Search for the term you want to replace with
/
usingctrl-l
to complete the full match. -
Use a blank substitution to replace items matching the last search
:s//new_text/g
(theg
will replace all occurrences found on that line).
Happy Vimming!