How do I change the case of matched text in a substitute replacement using \u, \U, \l, or \L modifiers?
Vim's substitute command supports case-change modifiers in the replacement string that let you capitalize, uppercase, or lowercase matched text as part of the s
category:
search
tags:
#search
#ex-commands
#substitute
#editing
How do I count the number of lines containing a pattern without making any replacements?
The n flag in the substitute command suppresses the actual replacement and instead reports the match count.
category:
search
tags:
#search
#ex-commands
#substitute
#normal-mode
How do I replace only part of a matched pattern using \zs and \ze in a substitution?
:%s/\zsparseData\ze(/processData/g
Vim's \zs and \ze atoms let you include context in your search pattern without including that context in the replacement.
category:
search
tags:
#search
#substitution
#regex
#editing
How do I join every line matching a pattern with the line that follows it?
The :g/pattern/join command combines the :global command with :join to merge every line matching a pattern with the line immediately following it.
category:
command-line
tags:
#ex-commands
#editing
#command-line
#search
#normal-mode
How do I search for a character by its ASCII or Unicode code point value in a Vim pattern?
Vim's regex engine supports special atoms that match characters by their numeric value rather than their glyph.
category:
search
tags:
#search
#editing
#normal-mode
How do I run a substitution only on lines that match a specific pattern using the global command?
:g/pattern1/s/pattern2/replacement/g
Combining :g with :s lets you apply a substitution using two independent patterns: :g selects which lines to act on, and :s controls what gets replaced within t
category:
command-line
tags:
#ex-commands
#search
#editing
#normal-mode
How do I replace each match with an incrementing number using a counter variable in Vim?
:let i=0 | g/pattern/s/pattern/\=printf('%d', i+=1)/
By combining :let, the :g global command, and an expression substitution with \=, you can replace every match of a pattern with a unique incrementing number.
category:
search
tags:
#search
#ex-commands
#registers
#editing
How do I search for a string containing special regex characters like dots or asterisks without escaping them?
Vim's default search mode gives special meaning to characters like .
category:
search
tags:
#search
#regex
#normal-mode
How do I run a substitution in Vim without getting an error when the pattern is not found?
:%s/pattern/replacement/ge
The e flag on :substitute silences the "Pattern not found" error that Vim normally reports when a substitution has no matches.
category:
search
tags:
#search
#ex-commands
#substitution
#macros
How do I make Vim's search stop at the end of the file instead of wrapping back to the top?
By default Vim's wrapscan option is enabled, which causes / and ? searches to wrap silently from the end of the file back to the beginning (and vice versa).
category:
config
tags:
#search
#config
#options
How do I use an atomic group in a Vim regex to prevent backtracking?
Vim's \@> syntax creates an atomic group in a regular expression.
category:
search
tags:
#search
#regex
#advanced-regex
#performance
How do I automatically apply the first spelling suggestion without opening the full suggestion list?
The z= command opens an interactive numbered menu of spelling corrections for the word under the cursor, requiring you to type a number and press Enter.
category:
editing
tags:
#editing
#normal-mode
#search
How do I permanently add a word to my personal spell file so Vim stops marking it as misspelled?
When Vim's spell checker flags a technical term, proper noun, or project-specific identifier as misspelled, you can permanently silence it with zg ("mark as goo
category:
config
tags:
#config
#editing
#search
How do I highlight a custom pattern in the current window without affecting the search register?
:call matchadd('ErrorMsg', 'TODO')
matchadd() lets you highlight arbitrary patterns using any highlight group — without touching the search register or search highlighting.
category:
config
tags:
#search
#config
#normal-mode
How do I use look-behind assertions in Vim regex to match text only when preceded by a pattern?
The \@<= operator is Vim's zero-width look-behind assertion.
category:
search
tags:
#search
#regex
#patterns
#normal-mode
How do I anchor a Vim search pattern to match only at the very start or end of the entire file?
Vim's ^ and $ anchors match the start and end of a line, but sometimes you need to match the very beginning or very end of the entire buffer.
category:
search
tags:
#search
#regex
#ex-commands
How do I run a command on every entry in the location list, like a window-local quickfix?
Vim maintains two parallel systems for collections of file positions: the quickfix list (global, one per Vim session) and the location list (local to each windo
category:
command-line
tags:
#command-line
#ex-commands
#buffers
#search
How do I delete all lines matching my last search pattern without retyping it?
:g//d uses an empty pattern in the global command, which instructs Vim to reuse the last search pattern.
category:
search
tags:
#search
#ex-commands
#global-command
#editing
How do I search for text that simultaneously matches two different patterns using Vim's AND operator?
Vim's \& operator lets you intersect two patterns so the match must satisfy both simultaneously.
category:
search
tags:
#search
#regex
#normal-mode
How do I write a non-greedy (lazy) quantifier in Vim's search regex?
In Vim's regex engine, \{-} is the non-greedy (lazy) quantifier — it matches as few characters as possible, unlike .
category:
search
tags:
#search
#regex
#patterns
#substitution