How do I append another pattern search to the current quickfix results?
:vimgrepadd /FIXME/j **/*.go
When you are triaging a codebase, one pattern is rarely enough.
:vimgrepadd /FIXME/j **/*.go
When you are triaging a codebase, one pattern is rarely enough.
/foo\zsbar\zebaz<CR>
Sometimes you need Vim to match a long structural pattern but only treat one piece of it as the actual match.
{count}n
Like most Vim motions, the n and N search repeat commands accept a count prefix.
:%s/\(\d\+\)/\=submatch(1)+1/g
Vim's substitute command supports using a VimScript expression as the replacement by prefixing it with \=.
:s#pattern#replacement#g
Vim's substitution command accepts any non-alphanumeric, non-whitespace character as the delimiter — not just /.
:keepmarks %s/pattern/replacement/g
The :keepmarks modifier prevents Vim from adjusting mark positions when a buffer-modifying command runs.
<C-l> during / search
When searching with incsearch enabled, Vim highlights matches as you type.
\%[seq]
Vim's \%[seq] atom makes the sequence seq optional in a pattern — matching any prefix of the sequence (including nothing).
\U, \L, \u, \l, \e in :substitute replacement
Vim's substitute command supports in-replacement case conversion metacharacters that transform the case of matched text without extra scripting.
:match {group} /pattern/
:match, :2match, and :3match give you three independent highlight slots that overlay patterns on the buffer using any highlight group — without touching the s
\%(pattern\)\@=
Vim's lookahead assertion \@= confirms that the current position is followed by a pattern — without including those characters in the match.
:s/\%Vfoo/bar/
The \%V atom in Vim's regex engine matches only within the area of the last visual selection.
search #search #visual-mode #substitute #advanced #ex-commands
:%s/^\(.\+\)\n\1$/\1/
This substitute command detects pairs of identical adjacent lines and collapses them into one, using a back-reference to match the repeated content.
cgn...{text}<Esc>.
The cgn + .
[[:alpha:]]
Vim's regex engine supports POSIX character classes inside bracket expressions, giving you locale-aware, readable alternatives to manual character ranges like [
\_.{-}
The \ modifier in Vim extends any character class or atom to also match newlines.
/pattern/e+2
Vim's search command supports an offset suffix that controls where the cursor lands after a match.
\%'m
Vim's \%'m regex atom matches the exact position of mark m in a search pattern.
:s/\v(\w+)\s+(\w+)/\2 \1/
By using capture groups in a substitute command with very magic mode (\v), you can swap two adjacent words in a single operation.
:s/pattern/~/
In a Vim substitution, using ~ as the replacement string repeats the replacement text from the most recent :s command.