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 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 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
How do I use \zs to set the start of a search match so only part of the pattern is highlighted or operated on?
Vim's \zs atom marks the start of the match within a longer pattern.
category:
search
tags:
#search
#regex
#patterns
#normal-mode
How do I change the case of captured text in a :substitute replacement?
\u / \l / \U / \L (in :s replacement)
Vim's :substitute replacement string supports case-conversion modifiers that let you uppercase or lowercase matched text without writing a separate command.
category:
search
tags:
#search
#editing
#ex-commands
#normal-mode
How do I write a Vim search pattern that matches text spanning multiple lines?
Vim's regex engine normally treats .
category:
search
tags:
#search
#regex
#normal-mode
How do I write a Vim regex that matches across multiple lines?
By default, .
category:
search
tags:
#search
#editing
#ex-commands
How do I limit a search or substitution to only the text I visually selected?
The \%V atom in a Vim pattern matches only inside the last visual selection.
category:
search
tags:
#search
#visual-mode
#substitute
#regex
#text-objects
How do I run a :g or :s command without overwriting my current search pattern?
Whenever Vim runs a command that involves searching — :g, :s, :v, or even moving the cursor with / — it overwrites the last search register (@/).
category:
search
tags:
#search
#ex-commands
#macros
How do I search for a pattern only within a visual selection?
The \%V pattern atom restricts a search to the region spanned by the last visual selection.
category:
search
tags:
#search
#visual-mode
#patterns
#normal-mode
How do I group regex atoms in Vim without creating a backreference?
In Vim's regex engine, \( and \) create a capturing group whose contents are stored in \1, \2, etc.
category:
search
tags:
#search
#regex
#ex-commands
#normal-mode
How do I restrict a search or substitution to exactly the characters I visually selected?
\%V (in search/substitute pattern)
The \%V atom in a Vim pattern matches only inside the last visual selection.
category:
search
tags:
#search
#visual-mode
#substitution
#regex
#normal-mode
How do I refer to the matched text in a Vim substitution replacement?
In a Vim substitution, & in the replacement string expands to the entire matched text.
category:
search
tags:
#search
#ex-commands
#editing
How do I convert text to title case (capitalize first letter, lowercase the rest of each word)?
Vim's substitute command supports case-conversion escape sequences in the replacement string.
category:
search
tags:
#search
#editing
#normal-mode
#ex-commands
How do I use capture groups in Vim substitutions to rearrange or swap matched text?
Vim's substitute command supports capture groups using \( and \) (or ( and ) in \v very-magic mode).
category:
search
tags:
#search
#editing
#substitution
#regex
#ex-commands
How do I restrict a Vim search to match only within a specific range of line numbers?
Vim's \%>{lnum}l and \%5l — matches only at positions after line 5 (i.
category:
search
tags:
#search
#regex
#navigation
#ex-commands
How do I search for and highlight text that exceeds a specific column width like 80 or 120?
The pattern /\%>80v.
category:
search
tags:
#search
#navigation
#normal-mode