How do you highlight search matches in Vim?
set hlsearch
Use set hlsearch to highlight all matches of the last search pattern.
set hlsearch
Use set hlsearch to highlight all matches of the last search pattern.
set ignorecase smartcase
Use ignorecase for case-insensitive search.
set incsearch
With set incsearch, Vim shows search matches as you type the pattern.
:%s/<C-r>a/replacement/g
In command-line mode, a inserts the contents of register a.
:let @/ = 'pattern'
Use :let @/ = 'pattern' to set the search register directly.
/<C-r>a
While in the search prompt (/), press a to insert the contents of register a.
:vimgrep /pattern/ **/*.py
By specifying a file glob pattern with :vimgrep, you can restrict the search to specific file types.
/pattern\{-}
The \{-} quantifier in Vim regex matches as few characters as possible, unlike which matches as many as possible (greedy).
:set shortmess-=S
The shortmess option controls which messages are shortened.
ciw + new text + Esc, then n.
The ciw command followed by new text, combined with and .
:s/pattern/replace/flags
The substitute command supports several flags that modify its behavior.
:%S/old/new/g (vim-abolish)
vim-abolish by Tim Pope provides :%S (Subvert), a substitute command that preserves the case pattern of the original text.
"/ register
The / register contains the most recent search pattern.
:g/pattern/norm @a
The :g/pattern/norm @a command combines the global command with macro execution.
v/pattern<CR>
Starting a search while in visual mode extends the selection to the search match.
y/\V<C-r>"<CR>
By yanking a visual selection and pasting it into the search prompt with \V (very nomagic), you can search for exact text including special characters.
:'<,'>s/\%Vpattern/replacement/g
Using \%V in a substitute pattern restricts matching to within the visual block area only, rather than the full lines.
:vimgrep /pattern/ **/*.ext
The :vimgrep command searches for a pattern across multiple files and populates the quickfix list with the results.
/\_.pattern
The \.
:grep pattern files
The :grep command runs an external grep tool and loads the results into Vim's quickfix list.