How do I search forward for text in Vim?
/{pattern}
The / command initiates a forward search in the file.
/{pattern}
The / command initiates a forward search in the file.
?{pattern}
The ? command searches backward from the cursor position.
:%s/\V literal.text/replacement/g
The \V (very nomagic) flag treats all characters as literal except for \.
:cdo s/old/new/g
The :cdo command executes a command on every entry in the quickfix list.
:set incsearch
The incsearch option enables incremental search, which highlights matches in real time as you type the search pattern.
/pattern/e
Search offsets let you place the cursor at a specific position relative to the match.
highlight TrailingWhitespace ctermbg=red and match TrailingWhitespace /\s\+$/
How it works Vim's highlight and match commands let you create custom visual indicators.
:%s/pattern/\=@a/g
How it works In Vim's substitute command, the replacement string can be a Vimscript expression when prefixed with \=.
/<C-r>0
How it works After yanking text, you can use it directly as a search pattern by inserting the yank register contents into the search prompt.
:set ignorecase smartcase
How it works By setting both ignorecase and smartcase, Vim uses an intelligent case sensitivity rule for searches: If your search pattern is all lowercase, the
/\%>5c\%<20cpattern
How it works Vim's search patterns support column position constraints using the \%c family of atoms.
:%s/\<word\>/replacement/g
How it works In Vim's regular expressions, \ are word boundary anchors: \ matches the end of a word.
\zs and \ze
How it works Vim's \zs (set start) and \ze (set end) atoms let you define which portion of a pattern counts as the actual match, even though the full pattern is
:g/pattern/t$
How it works The :g (global) command combined with :t (copy) lets you duplicate all lines matching a pattern to a specific location.
[I
How it works The [I command searches the current file (and included files) for the word under the cursor and displays a list of all matching lines with their li
\d \w \s \a \l \u
How it works Vim provides shorthand character classes that save you from writing out full bracket expressions.
.\{-}
How it works In most regex engines, ? or +? make quantifiers non-greedy (matching as little as possible).
/foo\|bar
How it works The \ operator in Vim's search pattern works like a logical OR, letting you match any one of several alternatives.
q/
How it works Vim keeps a history of all your search patterns.
/\cpattern
How it works By default, Vim searches are case-sensitive: /Hello will not match hello or HELLO.