How do I swap or rearrange text using captured groups in Vim substitution?
:%s/\(\w\+\) \(\w\+\)/\2 \1/g
Vim's substitute command supports captured groups (back-references) using \( and \), allowing you to capture parts of a match and rearrange them in the replacem
category:
search
tags:
#search
#substitute
#regex
#captured-groups
How do I search for a pattern that spans multiple lines in Vim?
Vim's regular expressions support multi-line matching through underscore-prefixed atoms.
category:
search
tags:
#search
#regex
#multiline
#patterns
How do I use POSIX character classes in Vim search patterns?
Vim supports POSIX character classes inside bracket expressions, providing a portable and readable way to match categories of characters.
category:
search
tags:
#search
#regex
#character-classes
#posix
How do I match only part of a search pattern in Vim using \zs and \ze?
Vim's \zs and \ze atoms let you control which part of a matched pattern gets highlighted and operated on.
category:
search
tags:
#search
#regex
#pattern-matching
#substitution
How do you use lookbehind in Vim search patterns?
Use \@<= for positive lookbehind.
category:
search
tags:
#search
#lookbehind
#regex
How do I restrict a search to only match within a specific line range?
Vim's \%>Nl and \%10l matches only after line 10 \%10l\%10l\%<20lold/new/g Combine with column restrictions for precise region targeting Tips Line numbers in \%
category:
search
tags:
#search
#regex
#range
#line-numbers
How do I search for a pattern only when it's preceded or followed by another pattern?
/\(pattern\)\@<=target or /target\(pattern\)\@=
Vim supports zero-width assertions (lookahead and lookbehind) in its regex engine.
category:
search
tags:
#search
#regex
#lookahead
#lookbehind
#advanced
How do I search and replace only within a visual block selection?
The \%V atom restricts a search pattern to match only within the visual selection area, including visual block selections.
category:
search
tags:
#search
#substitute
#visual-mode
#block-mode
#regex
How do I change the case of text during a search and replace?
Vim's substitute command supports case conversion modifiers in the replacement string.
category:
search
tags:
#search
#substitute
#regex
#text-manipulation
How do I search and replace only whole word matches, not partial matches?
Wrapping your search pattern in \ word boundary anchors ensures that Vim only matches the exact whole word, preventing accidental replacements inside longer wor
category:
search
tags:
#search
#substitution
#regex
#ex-commands
#editing
How do I use expressions in Vim's substitute replacement?
:%s/pattern/\=expression/g
Vim's substitute command supports expression replacements using \= in the replacement string.
category:
search
tags:
#search
#substitution
#ex-commands
#regex
#advanced
How do I use normal regex syntax in Vim search without escaping everything?
Vim's default regex syntax requires backslashes before most special characters like +, (, ), {, and , which is the opposite of what most developers expect from
category:
search
tags:
#search
#regex
#ex-commands
#productivity
#patterns
How do I search for a pattern that spans multiple lines?
Vim's default .
category:
search
tags:
#search
#regex
#patterns
#advanced
#multiline
How do I land the cursor a few lines above or below a search match?
Vim's search command accepts an offset after the pattern that shifts where the cursor lands relative to the match.
category:
search
tags:
#search
#navigation
#motions
#regex
#advanced
How do I search for text only within a visual selection?
The \%V atom restricts a search pattern to only match inside the most recent visual selection.
category:
search
tags:
#search
#visual-mode
#regex
#substitution
#advanced
How do I reuse my last search pattern in a substitute command without retyping it?
Leaving the search field empty in a :s command tells Vim to reuse the last search pattern from / or .
category:
search
tags:
#search
#substitution
#ex-commands
#regex
#productivity
How do I use capture groups to rearrange text in a Vim substitute command?
:%s/\(pattern1\)\(pattern2\)/\2\1/g
Vim's substitute command supports capture groups that let you match parts of text, remember them, and rearrange or reuse them in the replacement.
category:
search
tags:
#search
#substitution
#regex
#ex-commands
#editing