How do I use \zs to set the start of a search match so only part of the pattern is highlighted or operated on?
/prefix\zsword
Vim's \zs atom marks the start of the match within a longer pattern.
/prefix\zsword
Vim's \zs atom marks the start of the match within a longer pattern.
\u / \l / \U / \L (in :s replacement)
Vim's :substitute replacement string supports case-conversion modifiers that let you uppercase or lowercase matched text without writing a separate command.
:sort r /pattern/
The :sort r /pattern/ command sorts lines using the matched portion of the regex as the sort key.
:%s/\r//g
When a file created on Windows is opened in Vim on a Unix system, lines may retain \r (carriage return) characters, displayed as ^M at the end of each line.
/pattern1\_.{-}pattern2
Vim's regex engine normally treats .
\_.\+
By default, .
[i
Pressing [i in normal mode displays the first line above the cursor (including included files) that contains the keyword under the cursor.
:s/\v\w+/\U&/g
Vim's substitute command supports special case-conversion sequences in the replacement string, letting you transform matched text to upper or lower case without
:filter /pattern/ {command}
:filter /pattern/ {command} runs any Ex command but suppresses every output line that does not match the pattern.
:helpgrep
:helpgrep {pattern} searches all installed Vim help files for a pattern and populates the quickfix list with every match.
:Subvert
The vim-abolish plugin's :Subvert command (abbreviated :S) substitutes a word across all its case variants simultaneously.
:%s/pattern/\=expr/g
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.
\%V
The \%V atom in a Vim pattern matches only inside the last visual selection.
search #search #visual-mode #substitute #regex #text-objects
:keeppatterns {cmd}
Whenever Vim runs a command that involves searching — :g, :s, :v, or even moving the cursor with / — it overwrites the last search register (@/).
:Subvert/{src}/{tgt}/g
vim-abolish provides :Subvert, a smarter substitute that detects and preserves the case style of each match.
/\%V
The \%V pattern atom restricts a search to the region spanned by the last visual selection.
\%(pattern\)
In Vim's regex engine, \( and \) create a capturing group whose contents are stored in \1, \2, etc.
:cdo {cmd}
:cdo executes an Ex command on every entry in the quickfix list in sequence, visiting each match in turn.
\%V (in search/substitute pattern)
The \%V atom in a Vim pattern matches only inside the last visual selection.
search #search #visual-mode #substitution #regex #normal-mode
:%s/\w\+/(&)/g
In a Vim substitution, & in the replacement string expands to the entire matched text.