How do I restrict a search to only match within a specific line range?
Vim's \%>Nl and \%10l matches only after line 10 \%10l\%10l\%<20lold/new/g Combine with column restrictions for precise region targeting Tips Line numbers in \%
category:
search
tags:
#search
#regex
#range
#line-numbers
How do I make a macro that finds and operates on specific patterns?
qq /pattern<CR> {commands} q
By incorporating a search command inside a macro, you can make it jump to the next occurrence of a pattern before performing its edits.
category:
macros
tags:
#macros
#search
#recording
#workflow
#advanced
How do I search for a pattern only when it's preceded or followed by another pattern?
/\(pattern\)\@<=target or /target\(pattern\)\@=
Vim supports zero-width assertions (lookahead and lookbehind) in its regex engine.
category:
search
tags:
#search
#regex
#lookahead
#lookbehind
#advanced
How do I see all search matches highlighted as I type the pattern?
The combination of incsearch and hlsearch gives you live, interactive search highlighting.
category:
search
tags:
#search
#config
#highlighting
#workflow
How do I search across multiple files and navigate results without leaving Vim?
:vimgrep /pattern/g **/*.ext
The :vimgrep command searches for a pattern across multiple files and loads the results into the quickfix list.
category:
search
tags:
#search
#multi-file
#quickfix
#grep
#workflow
How do I quickly replace all occurrences of the word under my cursor?
Pressing searches for the word under the cursor, which also loads it into the search register.
category:
search
tags:
#search
#substitute
#workflow
#editing
#rename
How do I search and replace only within a visual block selection?
The \%V atom restricts a search pattern to match only within the visual selection area, including visual block selections.
category:
search
tags:
#search
#substitute
#visual-mode
#block-mode
#regex
How do I change the case of text during a search and replace?
Vim's substitute command supports case conversion modifiers in the replacement string.
category:
search
tags:
#search
#substitute
#regex
#text-manipulation
How do I paste or reuse my last search pattern?
Vim stores your last search pattern in the / register.
category:
registers
tags:
#registers
#search
#insert-mode
#command-line
How do I repeat my last substitution across the entire file?
The g& command repeats the last substitute command across the entire file.
category:
search
tags:
#search
#substitute
#ex-commands
#repeat
#workflow
How do I run a command on every file in the quickfix list?
:cdo s/old/new/g | update
The :cdo command executes a given command on every entry in the quickfix list.
category:
command-line
tags:
#command-line
#quickfix
#batch-editing
#search
#multi-file
How do I search for a pattern that spans multiple lines?
Vim's \ modifier makes any character class match newlines too.
category:
search
tags:
#search
#regex
#multiline
#pattern-matching
How do I jump to any location on screen using a two-character search in Vim?
The vim-sneak plugin by Justin Keyes provides a motion that lets you jump to any visible location by typing just two characters.
category:
plugins
tags:
#plugins
#sneak
#navigation
#motions
#search
How do I fuzzy search inside file contents across a project in Vim?
The fzf.
category:
plugins
tags:
#plugins
#fzf
#ripgrep
#search
#workflow
#quickfix
How do I search and replace a word while preserving its case variants in Vim?
The vim-abolish plugin by Tim Pope provides the :Subvert command (abbreviated :S), which performs search-and-replace operations that automatically handle every
category:
plugins
tags:
#plugins
#abolish
#search
#substitute
#refactoring
How do I search and replace only whole word matches, not partial matches?
Wrapping your search pattern in \ word boundary anchors ensures that Vim only matches the exact whole word, preventing accidental replacements inside longer wor
category:
search
tags:
#search
#substitution
#regex
#ex-commands
#editing
How do I search and replace with confirmation for each match?
Adding the c flag to a substitute command makes Vim pause at every match and ask you whether to replace it.
category:
search
tags:
#search
#substitution
#ex-commands
#editing
How do I use expressions in Vim's substitute replacement?
:%s/pattern/\=expression/g
Vim's substitute command supports expression replacements using \= in the replacement string.
category:
search
tags:
#search
#substitution
#ex-commands
#regex
#advanced
How do I use normal regex syntax in Vim search without escaping everything?
Vim's default regex syntax requires backslashes before most special characters like +, (, ), {, and , which is the opposite of what most developers expect from
category:
search
tags:
#search
#regex
#ex-commands
#productivity
#patterns
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