How do I run a substitution without overwriting my current search pattern?
The :keeppatterns modifier runs an Ex command — typically :s, :g, or :v — without modifying @/ (the last search pattern) or the command history.
category:
command-line
tags:
#ex-commands
#search
#substitution
#command-line
#scripting
How do I replace a character or pattern with a newline in a substitute command?
In Vim's substitute command, \r in the replacement string inserts a newline.
category:
editing
tags:
#editing
#substitute
#newline
#text-manipulation
How do I load multiple files matching a pattern into Vim for batch editing?
The :args command populates Vim's argument list with files matching a glob pattern, turning any set of files into a navigable list and enabling project-wide bat
category:
buffers-windows
tags:
#buffers
#ex-commands
#editing
#navigation
How do I highlight a custom pattern persistently in a window without changing the search register?
The matchadd() function adds a persistent highlight for a pattern in the current window without touching your search register or interfering with n/N navigation
category:
search
tags:
#search
#config
#visual-mode
#normal-mode
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 append another pattern search to the current quickfix results?
:vimgrepadd /FIXME/j **/*.go
When you are triaging a codebase, one pattern is rarely enough.
category:
search
tags:
#search
#quickfix
#project-workflow
#ex-commands
How do I jump to a definition-style pattern match using Vim's define search?
:djump searches for matches using Vim's definition search rules and jumps to the selected hit.
category:
navigation
tags:
#navigation
#search
#definitions
#command-line
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
How do I move through search matches while still typing the pattern?
While the search prompt is open (with incsearch enabled), pressing advances the cursor to the next match and moves it to the previous match — all without leav
category:
search
tags:
#search
#incsearch
#navigation
How do I limit a search pattern to a specific line range without using :global?
Vim regex supports position atoms that can constrain where a match is allowed to occur.
category:
search
tags:
#search
#regex
#patterns
#navigation
How do I highlight all occurrences of a yanked word without typing a search pattern?
After yanking text, you can promote it directly to the search register with :let @/ = @".
category:
registers
tags:
#registers
#search
#hlsearch
#normal-mode
How do I rerun a previous search pattern from history directly on the / prompt?
/\V<C-r>=histget('/', -2)<CR>
If you often alternate between two complex search patterns, opening q/ each time is slow.
category:
search
tags:
#search
#command-line
#history
#regex
#productivity
How do I make part of a search pattern optional so it matches with or without that sequence?
Vim's \%[seq] atom makes the sequence seq optional in a pattern — matching any prefix of the sequence (including nothing).
category:
search
tags:
#search
#editing
#ex-commands
How do I match text only when it is preceded by a specific pattern in Vim regex?
:%s/\(prefix\)\@<=target/replacement/g
Vim's \@<= is a zero-width look-behind assertion.
category:
search
tags:
#search
#regex
#substitution
#advanced
How do I run a substitute command without overwriting my current search pattern?
:keeppattern %s/old/new/g
When you run a :s or :%s substitute command, Vim updates the search register (@/) with the substitution pattern.
category:
command-line
tags:
#ex-commands
#search
#editing
#registers
#substitute
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 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 search for the contents of a register without typing the pattern manually?
Vim's search register (@/) holds the current search pattern — the same one used by n, N, *, and hlsearch highlighting.
category:
registers
tags:
#registers
#search
#normal-mode
#ex-commands
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 write a Vim search pattern that matches text spanning multiple lines?
Vim's regex engine normally treats .
category:
search
tags:
#search
#regex
#normal-mode