How do I apply the last substitution's replacement to a different search pattern without retyping it?
:~
The :~ command repeats the last substitution but uses the current search pattern instead of the original pattern.
:~
The :~ command repeats the last substitution but uses the current search pattern instead of the original pattern.
8g8
The 8g8 command searches forward from the cursor for the first byte that belongs to an invalid UTF-8 sequence.
:lua require('flash').jump()
flash.
:s/pattern/\U&/g
Vim's :substitute command supports case-transformation escape sequences in the replacement string.
search #search #substitute #ex-commands #editing #text-objects
:s/pattern/replacement/e
The e flag in Vim's :substitute command silently ignores the "E486: Pattern not found" error when the pattern does not match anything.
:g/outer/,/end/g/inner/
The :global command accepts a range, which lets you scope its search to sections of the file rather than the entire buffer.
\@<= and \@<!
Vim's \@<= and \@<! atoms let you write zero-width lookbehind assertions — they check what comes before the match position without consuming characters.
:s/\n/ /
One of the most confusing asymmetries in Vim's substitution syntax: \n and \r mean different things depending on whether they appear in the pattern or the repla
nzz
Typing nzz chains two normal-mode commands: n jumps to the next match of the last search, and zz immediately redraws the screen so the cursor line is vertically
:set gdefault
By default, :s/old/new/ only replaces the first occurrence of a pattern on each line.
:%s/\w\+/\u&/g
Vim's substitute command supports case-conversion modifiers in the replacement string.
[/
When editing code, you often need to navigate to the boundaries of multi-line block comments (/ .
/\c
Vim lets you override the ignorecase and smartcase settings on a per-search basis using the \c (case-insensitive) and \C (case-sensitive) atoms directly inside
:let @/ = @a
Vim's search register (@/) holds the current search pattern — the same one used by n, N, *, and hlsearch highlighting.
\@!
In Vim's regex engine, \@! is the negative lookahead assertion.
:lgrep {pattern} {files}
The location list is a per-window counterpart to the global quickfix list.
buffers-windows #buffers-windows #ex-commands #search #navigation
:g/pattern/t.
Combining :global with the :t (copy) command and the .
[d
The [d command searches from the beginning of the file for the first line matching the define pattern for the word under the cursor, and displays it in the stat
:colder
Vim maintains a history stack of up to 10 quickfix lists.
buffers-windows #buffers-windows #navigation #ex-commands #search
\%[abc]
The \%[.