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 restrict a search or substitution to exactly the characters I visually selected?
\%V (in search/substitute pattern)
The \%V atom in a Vim pattern matches only inside the last visual selection.
category:
search
tags:
#search
#visual-mode
#substitution
#regex
#normal-mode
How do I gather all matches from the current file into a location list without moving the cursor?
When you want a searchable list of matches without leaving your current editing context, :lvimgrep is a strong alternative to regular / navigation.
category:
search
tags:
#search
#quickfix
#location-list
#ex-commands
How do I use a Vimscript expression as the replacement in a substitute command?
Prefixing the replacement field of :s with \= tells Vim to evaluate the rest as a Vimscript expression and use its result as the replacement string.
category:
editing
tags:
#search
#editing
#substitute
#regex
#ex-commands
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 load the search register with a literal <cword> pattern?
:let @/ = '\V' .. escape(expand('<cword>'), '\\')
Sometimes * is too opinionated: it uses keyword boundaries and interprets regex metacharacters.
category:
search
tags:
#search
#registers
#ex-commands
#regex
#navigation
How do I use a VimScript expression as the replacement in a substitution?
:s/pattern/\=expression/g
Prefixing the replacement string with \= in a :substitute command tells Vim to evaluate the rest as a VimScript expression rather than literal text.
category:
search
tags:
#search
#ex-commands
#editing
#normal-mode
How do I search across files with lvimgrep and keep results in a window-local location list?
:lvimgrep /pattern/j **/* | lopen
Quickfix is great, but it is global.
category:
search
tags:
#search
#location-list
#quickfix
#project-navigation
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 search a project without overwriting the global quickfix list?
:lvimgrep /pattern/gj **/*.js | lopen
When you already rely on the global quickfix list for compiler errors or another search, running :vimgrep can wipe that context.
category:
search
tags:
#search
#command-line
#quickfix
#navigation
How do I force a case-sensitive or case-insensitive search for just one pattern without changing my settings?
Vim's \C and \c atoms let you override ignorecase and smartcase on a per-pattern basis.
category:
search
tags:
#search
#normal-mode
#ex-commands
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 use a Vimscript expression to compute the replacement text in a substitution?
Prefixing the replacement field of :s with \= makes Vim evaluate the rest as a Vimscript expression and use the result as the replacement string.
category:
command-line
tags:
#search
#ex-commands
#editing
#command-line
How do I match only part of a search pattern in Vim using \zs and \ze?
Vim's \zs and \ze atoms let you control which part of a matched pattern gets highlighted and operated on.
category:
search
tags:
#search
#regex
#pattern-matching
#substitution
How do I search a whole project and open all matches in quickfix with built-in Vim commands?
:vimgrep /pattern/j **/*<CR>:copen<CR>
When you need a project-wide search but do not want to leave Vim, :vimgrep gives you a built-in grep workflow with navigation, filtering, and batch editing thro
category:
search
tags:
#search
#quickfix
#vimgrep
#project-workflow
#command-line
How do I force a case-insensitive substitution without changing the global ignorecase setting?
:%s/pattern/replacement/ig
The :s substitute command accepts /i and /I flags that override your global ignorecase and smartcase settings for that single substitution, letting you choose c
category:
search
tags:
#search
#editing
#ex-commands
#normal-mode
How do I use a Vim expression to dynamically compute substitution replacement text?
The \= prefix in the replacement field of :s/// tells Vim to evaluate the right-hand side as a Vim script expression and use the result as the replacement text.
category:
search
tags:
#search
#substitution
#ex-commands
How do I use a register value as the replacement string in a substitution?
How it works In Vim's substitute command, the replacement string can be a Vimscript expression when prefixed with \=.
category:
registers
tags:
#registers
#search
#ex-commands
#editing
How do I see search results as I type the pattern?
The incsearch option enables incremental search, which highlights matches in real time as you type the search pattern.
category:
search
tags:
#search
#config
How do I search files on 'path' and open the first match in the preview window instead of replacing my current buffer?
When you need quick context from another file but do not want to disturb your current editing window, :psearch gives you a clean workflow.
category:
buffers-windows
tags:
#buffers
#windows
#preview-window
#search
#navigation