How do I search for a pattern across multiple files and navigate the results?
:vimgrep /pattern/ **/*.ext | copen
The :vimgrep command searches for a regex pattern across multiple files and populates the quickfix list with every match.
category:
search
tags:
#search
#quickfix
#ex-commands
#navigation
#productivity
#grep
How do I search for a pattern that spans multiple lines?
Vim's default .
category:
search
tags:
#search
#regex
#patterns
#advanced
#multiline
How do I search and replace text across multiple files in Vim?
:args **/*.py | argdo %s/old/new/gc | update
Vim can perform search-and-replace across multiple files without any plugins by combining the arglist with :argdo.
category:
search
tags:
#search
#substitution
#ex-commands
#productivity
#quickfix
#arglist
How do I land the cursor a few lines above or below a search match?
Vim's search command accepts an offset after the pattern that shifts where the cursor lands relative to the match.
category:
search
tags:
#search
#navigation
#motions
#regex
#advanced
How do I search for text only within a visual selection?
The \%V atom restricts a search pattern to only match inside the most recent visual selection.
category:
search
tags:
#search
#visual-mode
#regex
#substitution
#advanced
How do I search for the word under the cursor without whole-word boundaries?
The g command searches forward for the text under the cursor without adding word boundary anchors.
category:
search
tags:
#search
#navigation
#normal-mode
#motions
#productivity
How do I repeat the last substitute command quickly?
The & command in normal mode repeats the last :s substitution on the current line.
category:
search
tags:
#search
#substitution
#ex-commands
#repeat
#normal-mode
How do I reuse my last search pattern in a substitute command without retyping it?
Leaving the search field empty in a :s command tells Vim to reuse the last search pattern from / or .
category:
search
tags:
#search
#substitution
#ex-commands
#regex
#productivity
How do I visually select the next occurrence of my last search pattern?
The gn motion searches forward for the next match of the last search pattern and visually selects it.
category:
search
tags:
#navigation
#search
#motions
#normal-mode
#repeat
#editing
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 use capture groups to rearrange text in a Vim substitute command?
:%s/\(pattern1\)\(pattern2\)/\2\1/g
Vim's substitute command supports capture groups that let you match parts of text, remember them, and rearrange or reuse them in the replacement.
category:
search
tags:
#search
#substitution
#regex
#ex-commands
#editing
How do I search for text in Vim?
The /pattern command searches forward through the file for the given pattern.
category:
search
tags:
#search
#navigation
#normal-mode
How do I search backward for the word under the cursor?
The # command searches backward for the exact word under the cursor, jumping to the previous occurrence.
category:
search
tags:
#search
#navigation
#normal-mode
How do I search for the word under the cursor?
The command searches forward for the exact word under the cursor, jumping to the next occurrence.
category:
search
tags:
#search
#navigation
#normal-mode
How do I search and replace text only on the current line?
The :s/old/new/g command replaces all occurrences of old with new on the current line only.
category:
search
tags:
#search
#ex-commands
#editing
How do I search backward in Vim?
The ?pattern command searches backward through the file for the given pattern, starting from the cursor position and wrapping around to the end of the file if n
category:
search
tags:
#search
#navigation
#normal-mode
How do I jump to the local definition of a variable in Vim?
The gd command jumps to the local definition of the word under the cursor.
category:
navigation
tags:
#navigation
#motions
#normal-mode
#search
How do I run a normal mode command on every line matching a pattern?
The :g/pattern/normal {commands} command executes normal mode keystrokes on every line in the file that matches the given pattern.
category:
command-line
tags:
#ex-commands
#command-line
#editing
#search
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 clear search highlighting in Vim?
The :noh (short for :nohlsearch) command clears the highlighting from the last search pattern.
category:
search
tags:
#search
#ex-commands
#config