How do I strip trailing whitespace without clobbering my last search pattern?
:keeppatterns %s/\s\+$//e
Bulk cleanup commands often damage your navigation flow by overwriting the last search pattern (@/).
category:
command-line
tags:
#command-line
#search
#substitution
#whitespace
How do I search only a sub-part of a larger pattern using \zs and \ze?
Sometimes you need Vim to match a long structural pattern but only treat one piece of it as the actual match.
category:
search
tags:
#search
#regex
#pattern-matching
#advanced
How do I jump to the Nth next search match instead of pressing n repeatedly?
Like most Vim motions, the n and N search repeat commands accept a count prefix.
category:
search
tags:
#search
#navigation
#motions
How do I delete all lines between two delimiter patterns without removing the delimiters themselves?
:g/BEGIN/+1,/END/-1 delete
By combining the :global command with a relative address range, you can delete the content between repeating delimiter pairs while leaving the delimiters intact
category:
command-line
tags:
#command-line
#ex-commands
#search
#editing
How do I use an expression in a substitution to perform arithmetic on matched numbers?
:%s/\(\d\+\)/\=submatch(1)+1/g
Vim's substitute command supports using a VimScript expression as the replacement by prefixing it with \=.
category:
search
tags:
#search
#substitution
#expressions
#editing
How do I yank text from the cursor to the next occurrence of a pattern without entering visual mode?
Any operator in Vim can take a search motion as its argument.
category:
editing
tags:
#editing
#search
#motions
#normal-mode
How do I avoid backslash-escaping slashes in a substitution when replacing file paths or URLs?
Vim's substitution command accepts any non-alphanumeric, non-whitespace character as the delimiter — not just /.
category:
search
tags:
#search
#ex-commands
#editing
How do I run a find-and-replace across multiple files at once using the argument list?
:args **/*.py | argdo %s/old/new/ge | update
Combining :args, :argdo, and :update gives you a powerful in-editor multi-file search and replace without leaving Vim.
category:
command-line
tags:
#ex-commands
#editing
#macros
#search
How do I run a substitution without displacing my marks?
:keepmarks %s/pattern/replacement/g
The :keepmarks modifier prevents Vim from adjusting mark positions when a buffer-modifying command runs.
category:
search
tags:
#marks
#search
#editing
#ex-commands
How do I extend my incremental search pattern one character at a time from the current match without retyping?
When searching with incsearch enabled, Vim highlights matches as you type.
category:
search
tags:
#search
#incsearch
#normal-mode
How do I jump to any visible text on screen with a two-character search using flash.nvim in Neovim?
flash.
category:
plugins
tags:
#navigation
#motions
#plugins
#search
How do I run a global command only on lines that match two different patterns simultaneously?
:g/pattern1/g/pattern2/command
Vim's :g command can be nested — the command part of one :g can itself be another :g.
category:
command-line
tags:
#ex-commands
#search
#editing
#command-line
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 use gn as a text object to delete or yank the next search match?
The gn motion is a versatile text object that selects the next occurrence of the last search pattern.
category:
editing
tags:
#editing
#search
#text-objects
#normal-mode
#motions
How do I use case conversion metacharacters in Vim substitution replacement strings?
\U, \L, \u, \l, \e in :substitute replacement
Vim's substitute command supports in-replacement case conversion metacharacters that transform the case of matched text without extra scripting.
category:
search
tags:
#search
#ex-commands
#normal-mode
How do I persistently highlight a pattern in Vim using a specific highlight group without a plugin?
:match, :2match, and :3match give you three independent highlight slots that overlay patterns on the buffer using any highlight group — without touching the s
category:
search
tags:
#search
#config
#normal-mode
#ex-commands
How do I write a Vim regex lookahead that doesn't consume a capture group slot?
Vim's lookahead assertion \@= confirms that the current position is followed by a pattern — without including those characters in the match.
category:
search
tags:
#search
#regex
#lookahead
#patterns
#normal-mode
How do I jump to a tag matching a partial name or pattern when I don't know the exact tag name?
:tjump is a smarter variant of :tag.
category:
navigation
tags:
#navigation
#tags
#search
How do I jump to the next misspelled word in my buffer using Vim's built-in spell check?
When spell checking is enabled with :set spell, Vim underlines misspelled words in the buffer.
category:
navigation
tags:
#navigation
#search
#spelling
How do I restrict a substitute command to only the text within my last visual selection using the percent-V atom?
The \%V atom in Vim's regex engine matches only within the area of the last visual selection.
category:
search
tags:
#search
#visual-mode
#substitute
#advanced
#ex-commands