How do I access and manipulate the last search pattern as a register?
"/
Vim stores the last search pattern in the special / register.
"/
Vim stores the last search pattern in the special / register.
:keeppatterns %s/old/new/g
The :keeppatterns modifier runs any Ex command without modifying Vim's last search pattern (stored in @/).
command-line #search #ex-commands #command-line #substitute #registers
<C-x>s
When spell checking is enabled (:set spell), s in insert mode opens a popup menu of suggested corrections for the most recently flagged misspelled word — with
]s / [s / z=
Vim has a built-in spell checker that highlights misspelled words and provides correction suggestions — all without plugins.
* (in visual mode)
In normal mode, searches for the word under the cursor with word-boundary anchors.
\v
Vim's default regex mode ("magic") requires backslashes before many special characters: \(, \ , \+, \{.
:keeppatterns {command}
The :keeppatterns modifier runs an Ex command — typically :s, :g, or :v — without modifying @/ (the last search pattern) or the command history.
command-line #ex-commands #search #substitution #command-line #scripting
:g/start/,/end/d
The :g (global) command can operate on ranges, not just single lines.
:vimgrep /pattern/ **/*
While external tools like grep or ripgrep are fast, Vim's built-in :vimgrep has a key advantage: it populates the quickfix list directly, so you can jump betwee
:s/\v(pattern1)(pattern2)/\2\1/
Vim's substitute command supports capture groups (also called backreferences), which let you rearrange matched portions of text.
:g/pattern/.-1,.+1d
The :g (global) command normally operates on lines that match a pattern.
:cexpr system('grep -rn TODO .')
The :cexpr command evaluates an expression and parses the result as quickfix entries using the current errorformat.
:%s/^/\=line('.').' '/
Vim's substitute command supports expressions in the replacement string using \=.
:keeppattern s/old/new/g
When you run a :s or :g command, Vim updates the search register (@/) with the pattern you used.
:tag /pattern
When working with ctags, you typically jump to exact tag names with .
:g/pattern/z#.5
The :global command is great for finding lines matching a pattern, but by default it only shows the matching lines themselves.
/\(\<\w\+\>\)\_s\+\1\>
When writing or editing text, repeated words like "the the" or "is is" are a common typo that spell checkers often miss.
/\v(pattern)@<=match
Vim supports zero-width assertions (lookahead and lookbehind) in its regex engine.
search #search #regex #advanced-search #lookahead #lookbehind
:/start/,/end/d
Instead of specifying line numbers for Ex command ranges, you can use search patterns.
command-line #ex-commands #editing #search #ranges #command-line
:vimgrep /pattern/j **/*
By default, :vimgrep jumps your cursor to the first match it finds, which can be disorienting when you just want to collect results and browse them on your own