How do I highlight trailing whitespace with a custom color in Vim?
highlight TrailingWhitespace ctermbg=red and match TrailingWhitespace /\s\+$/
How it works Vim's highlight and match commands let you create custom visual indicators.
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.
:'<,'>g/pattern/command
How it works The :g (global) command is one of Vim's most powerful features.
qa:s/old/new/g<CR>jq
How it works You can combine Ex commands like :s (substitute) with macro recording to create powerful repeatable find-and-replace operations that go beyond what
:Telescope live_grep
Telescope's livegrep picker provides real-time regex search across your entire project as you type.
:%s/pattern/\=MyFunc(submatch(0))/g
The \= prefix in Vim's substitute replacement invokes the expression register, which can call any Vimscript function.
:%s/pattern/\=@0/g
The \=@0 replacement expression inserts the contents of register 0 (last yank) as the replacement text.
/pattern/+N or /pattern/-N
Vim's search command accepts an offset that places your cursor on a line relative to the match.