How do I force a case-sensitive search in Vim even when ignorecase is enabled?
Appending \C anywhere in a search pattern forces the entire search to be case-sensitive, regardless of whether ignorecase or smartcase is set.
category:
search
tags:
#search
#case-sensitive
#ignorecase
#smartcase
#normal-mode
How do I configure Vim's :grep command to use a faster external search tool like ripgrep or ag?
:set grepprg={cmd} grepformat={fmt}
Vim's :grep command delegates to an external tool defined by grepprg, then parses the output according to grepformat to populate the quickfix list.
category:
search
tags:
#search
#ex-commands
#config
#buffers
How do I match a pattern only when preceded or followed by another pattern using zero-width assertions?
Vim's regex engine supports zero-width lookahead and lookbehind assertions — \@= and \@<= — which let you match text based on surrounding context without in
category:
search
tags:
#search
#regex
#advanced
#patterns
#substitution
How do I apply the last substitution's replacement to a different search pattern without retyping it?
The :~ command repeats the last substitution but uses the current search pattern instead of the original pattern.
category:
search
tags:
#search
#editing
#ex-commands
#substitution
How do I transform matched text to uppercase or lowercase directly inside a substitute replacement?
Vim's :substitute command supports case-transformation escape sequences in the replacement string.
category:
search
tags:
#search
#substitute
#ex-commands
#editing
#text-objects
How do I suppress the 'Pattern not found' error when a substitution has no match?
The e flag in Vim's :substitute command silently ignores the "E486: Pattern not found" error when the pattern does not match anything.
category:
search
tags:
#search
#substitute
#ex-commands
#macros
#editing
How do I use zero-width lookbehind assertions in Vim search patterns to match text only when preceded (or not preceded) by a pattern?
Vim's \@<= and \@<! atoms let you write zero-width lookbehind assertions — they check what comes before the match position without consuming characters.
category:
search
tags:
#search
#regex
#patterns
#advanced
What is the difference between \n and \r in Vim substitution patterns and replacements?
One of the most confusing asymmetries in Vim's substitution syntax: \n and \r mean different things depending on whether they appear in the pattern or the repla
category:
search
tags:
#search
#ex-commands
#editing
How do I capitalize the first letter of every word in a file using a substitute command?
Vim's substitute command supports case-conversion modifiers in the replacement string.
category:
search
tags:
#search
#ex-commands
#editing
#normal-mode
How do I override Vim's case sensitivity for a single search without changing the global ignorecase setting?
Vim lets you override the ignorecase and smartcase settings on a per-search basis using the \c (case-insensitive) and \C (case-sensitive) atoms directly inside
category:
search
tags:
#search
#navigation
#patterns
#normal-mode
How do I match a pattern only when it is NOT followed by another pattern in Vim regex?
In Vim's regex engine, \@! is the negative lookahead assertion.
category:
search
tags:
#search
#regex
#patterns
How do I view the first macro or keyword definition without leaving my current position?
The [d command searches from the beginning of the file for the first line matching the define pattern for the word under the cursor, and displays it in the stat
category:
search
tags:
#search
#navigation
#normal-mode
How do I match an optional sequence of characters at the end of a word in a Vim regex?
The \%[.
category:
search
tags:
#search
#regex
#normal-mode
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 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 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