How do I move through search matches while still typing the pattern?
<C-g> and <C-t>
While the search prompt is open (with incsearch enabled), pressing advances the cursor to the next match and moves it to the previous match — all without leav
<C-g> and <C-t>
While the search prompt is open (with incsearch enabled), pressing advances the cursor to the next match and moves it to the previous match — all without leav
:%s/pattern/\U&/g
Vim's substitute replacement string supports special case-transform atoms that change the case of matched text without requiring a second pass or an external to
\@= and \@! and \@<= and \@<!
Vim's regex engine supports zero-width lookahead and lookbehind assertions using the \@=, \@!, \@<=, and \@<! atoms.
g* and g#
The and # commands search for the exact whole word under the cursor (with word boundaries \).
"/
Vim stores the last search pattern in the special / register.
:keeppatterns
Normally, any command that uses a pattern — including :substitute, :global, and :vimgrep — replaces the current search register @/ with the new pattern.
:%s/pattern//gn
The n flag on the substitute command reports the number of matches without performing any substitution.
:keeppatterns %s/old/new/g
The :keeppatterns modifier runs any Ex command without modifying Vim's last search pattern (stored in @/).
command-line #search #ex-commands #command-line #substitute #registers
<C-x>s
When spell checking is enabled (:set spell), s in insert mode opens a popup menu of suggested corrections for the most recently flagged misspelled word — with
:%s/pattern//gn
The n flag on the substitute command makes it report the match count without actually performing any replacement.
]s / [s / z=
Vim has a built-in spell checker that highlights misspelled words and provides correction suggestions — all without plugins.
* (in visual mode)
In normal mode, searches for the word under the cursor with word-boundary anchors.
\v
Vim's default regex mode ("magic") requires backslashes before many special characters: \(, \ , \+, \{.
:keeppatterns {command}
The :keeppatterns modifier runs an Ex command — typically :s, :g, or :v — without modifying @/ (the last search pattern) or the command history.
command-line #ex-commands #search #substitution #command-line #scripting
:g/start/,/end/d
The :g (global) command can operate on ranges, not just single lines.
:vimgrep /pattern/ **/*
While external tools like grep or ripgrep are fast, Vim's built-in :vimgrep has a key advantage: it populates the quickfix list directly, so you can jump betwee
:s/\v(pattern1)(pattern2)/\2\1/
Vim's substitute command supports capture groups (also called backreferences), which let you rearrange matched portions of text.
:keeppattern %s/pattern/replacement/g
When you run a :substitute command, Vim updates the search register (@/) with the substitute pattern, which changes your hlsearch highlighting and affects n/N n
:g/pattern/.-1,.+1d
The :g (global) command normally operates on lines that match a pattern.
:cexpr system('grep -rn TODO .')
The :cexpr command evaluates an expression and parses the result as quickfix entries using the current errorformat.