Vim 9 cheatsheet

Vim 9: Searching and replacing

9 common Vim 9 tasks.

Search forward

Search for text below the cursor. Press n for the next match and N for the previous one.

/pattern

Search backward

Search for text above the cursor.

?pattern

Search for the word under the cursor

Jump to the next occurrence of the word under the cursor.

*

Replace in the whole file

Replace every occurrence of old with new.

:%s/old/new/g

Replace with confirmation

Ask before each replacement.

:%s/old/new/gc

Replace in a selection

After selecting lines in visual mode, replace only inside them. Vim fills in the range.

:'<,'>s/old/new/g

Clear search highlighting

Turn off the highlight until the next search.

:nohlsearch

Delete all lines matching a pattern

Delete every line that contains the pattern.

:g/pattern/d

Caution: Check the pattern with a search first. Undo with u if it removes too much.

Ignore case unless you type capitals

Make searches case-insensitive unless the pattern has an uppercase letter.

:set ignorecase smartcase

Was this page helpful?