How do I delete all lines that do NOT match a pattern?
The :v command (short for :vglobal) is the inverse of :g — it executes a command on every line that does not match the given pattern.
category:
command-line
tags:
#editing
#ex-commands
#search
#filtering
#productivity
How do I extend a visual selection to a search match?
Starting a search while in visual mode extends the selection to the search match.
category:
visual-mode
tags:
#visual-mode
#search
How do I search for tag definitions using a regex pattern instead of an exact name?
When working with ctags, you typically jump to exact tag names with .
category:
navigation
tags:
#navigation
#search
#ex-commands
How do I add another project-wide pattern search without replacing my current quickfix results?
:vimgrepadd /pattern/j **/*<CR>
When you are investigating code, you often need to collect several related patterns before deciding what to edit.
category:
search
tags:
#search
#quickfix
#command-line
#navigation
How do I search with vimgrep only in specific file types?
:vimgrep /pattern/ **/*.py
By specifying a file glob pattern with :vimgrep, you can restrict the search to specific file types.
category:
search
tags:
#search
#ex-commands
How do I duplicate every line matching a pattern, placing a copy directly below each one?
Combining :global with the :t (copy) command and the .
category:
command-line
tags:
#editing
#ex-commands
#search
#command-line
How do I run a command on every line matching a pattern?
The :g/pattern/command (global) command executes an Ex command on every line in the file that matches the given pattern.
category:
command-line
tags:
#ex-commands
#search
#editing
#command-line
How do I run normal mode edits on every line matching a pattern?
The :global command combined with :normal lets you execute arbitrary normal mode keystrokes on every line that matches a pattern.
category:
command-line
tags:
#global
#normal-mode
#editing
#ex-commands
#batch-editing
How do I delete the line immediately following every line that matches a pattern?
Using :g/pattern/+1d you can delete the line that comes right after each line matching a pattern, in one pass.
category:
command-line
tags:
#ex-commands
#editing
#search
#command-line
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 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 search for a pattern across all files in my project with Vim's built-in grep?
:vimgrep /pattern/ (shortened to :vim) is Vim's built-in project-wide search.
category:
command-line
tags:
#search
#ex-commands
#navigation
#command-line
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
How do I open a file in a split window and jump directly to the first match of a pattern?
The +{cmd} syntax lets you run an Ex command immediately after a file is opened.
category:
buffers-windows
tags:
#buffers-windows
#navigation
#ex-commands
How do I filter the output of a Vim command to show only lines matching a pattern?
:filter /pattern/ {command}
:filter /pattern/ {command} runs any Ex command but suppresses every output line that does not match the pattern.
category:
command-line
tags:
#command-line
#ex-commands
#search
#buffers
How do I search for a pattern in the current file and navigate results with the quickfix list?
When you need to find all occurrences of a pattern in the current file and jump between them systematically, :vimgrep with % is more powerful than basic / searc
category:
search
tags:
#search
#quickfix
#ex-commands
#navigation
How do I view only command-history entries matching a pattern in Vim?
:filter /{pattern}/ history cmd
When command history gets crowded, scanning :history cmd manually is slow.
category:
command-line
tags:
#command-line
#history
#search
#workflow
How do I populate the argument list with a glob pattern to work across multiple files?
The :args command sets Vim's argument list to all files matching a glob pattern.
category:
command-line
tags:
#command-line
#buffers
#ex-commands
#editing
How do I move all lines matching a pattern to the end of the file in Vim?
The :g (global) command combined with :m (move) lets you collect all lines matching a pattern and relocate them to a specific position in the file.
category:
command-line
tags:
#ex-commands
#editing
#global
#search
#formatting
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