How do I search for a pattern only on a specific line number or at a specific column position?
Vim's \%l and \%c pattern atoms anchor a search to a particular line number or column, enabling surgical searches and substitutions that standard regex cannot e
category:
search
tags:
#search
#regex
#ex-commands
How do I match a pattern only when followed or preceded by another pattern in Vim?
\@= and \@! and \@<= and \@<!
Vim's regex engine supports zero-width lookahead and lookbehind assertions using the \@=, \@!, \@<=, and \@<! atoms.
category:
search
tags:
#search
#regex
#normal-mode
How do I use PCRE-style regex in Vim without escaping every special character?
Vim's default regex mode ("magic") requires backslashes before many special characters: \(, \ , \+, \{.
category:
search
tags:
#search
#regex
#patterns
#normal-mode
How do I swap two parts of a line using capture groups in a Vim substitution?
:s/\v(pattern1)(pattern2)/\2\1/
Vim's substitute command supports capture groups (also called backreferences), which let you rearrange matched portions of text.
category:
search
tags:
#search
#substitute
#regex
#editing
#ex-commands
How do I search for a pattern only within specific columns of a line?
When working with columnar data like CSV files, log files, or fixed-width records, you often need to match a pattern only when it appears in a specific column r
category:
search
tags:
#search
#regex
#navigation
#ex-commands
How do I search for text that appears after or before a specific pattern without including the pattern in the match?
Vim supports zero-width assertions (lookahead and lookbehind) in its regex engine.
category:
search
tags:
#search
#regex
#advanced-search
#lookahead
#lookbehind
How do I match only part of a search pattern in Vim using \zs and \ze?
Vim's \zs (start of match) and \ze (end of match) atoms let you control which portion of a pattern is treated as the actual match.
category:
search
tags:
#search
#regex
#substitution
#ex-commands
#editing
How do I match only part of a search pattern in Vim using \zs and \ze?
Vim's \zs (start of match) and \ze (end of match) atoms let you define a search pattern but only highlight or operate on a portion of it.
category:
search
tags:
#search
#regex
#substitution
#ex-commands
#editing
How do I search for patterns only at specific line or column positions in Vim?
Vim provides position-matching atoms that constrain where a pattern can match based on line numbers, column positions, or virtual columns.
category:
search
tags:
#search
#regex
#position
#columns
How do I search for a pattern repeated an exact number of times in Vim?
Vim supports counted quantifiers that let you specify exactly how many times a pattern should repeat.
category:
search
tags:
#search
#regex
#quantifiers
#patterns
How do I search using lookahead and lookbehind patterns in Vim?
Vim supports zero-width assertions (lookahead and lookbehind) in its regex engine, allowing you to match text based on what precedes or follows it without inclu
category:
search
tags:
#search
#regex
#patterns
#advanced-search
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 search for multiple alternative patterns at once in Vim?
Vim's search supports alternation with the \ operator, allowing you to find any one of several patterns in a single search.
category:
search
tags:
#search
#regex
#alternation
#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