How do I convert text to title case (capitalize first letter, lowercase the rest of each word)?
:%s/\(\w\+\)/\u\L\1/g
Vim's substitute command supports case-conversion escape sequences in the replacement string.
:%s/\(\w\+\)/\u\L\1/g
Vim's substitute command supports case-conversion escape sequences in the replacement string.
:s/\v(\w+) (\w+)/\2 \1/
Vim's substitute command supports capture groups using \( and \) (or ( and ) in \v very-magic mode).
:e +/pattern filename
The +{cmd} flag on :edit (and most file-opening commands) runs an Ex command immediately after the file loads.
command-line #command-line #ex-commands #navigation #search #buffers
/\%>5l\%<10l pattern
Vim's \%>{lnum}l and \%5l — matches only at positions after line 5 (i.
/\%>80v.
The pattern /\%>80v.
d/{pattern}<CR>
Vim lets you use a / search as a motion for any operator.
:g/pattern/d A
Using :g/pattern/d A you can sweep through the entire buffer and extract every line that matches a pattern into register a, removing them from the buffer in the
\%#
The \%# atom in Vim's regex engine matches the exact position of the cursor — zero-width, between characters.
:s/pattern/\=expression/
The \= prefix in the replacement field of :s/// tells Vim to evaluate the right-hand side as a Vim script expression and use the result as the replacement text.
\%>20c
The \%Nc, \%>Nc, and \%20c — match only after column 20 (i.
:vimgrep // **/*.txt
Using // (an empty pattern) in :vimgrep tells Vim to reuse the last search pattern.
:/pattern1/,/pattern2/
Ex command ranges in Vim are not limited to line numbers and marks — you can use /pattern/ as a range boundary to select lines between any two matching patter
/colour\%[s]
Vim's \%[.
\c
Vim lets you embed \c or \C directly inside a search pattern to control case sensitivity for that search only, regardless of your 'ignorecase' and 'smartcase' s
:s/pattern/\=expr/g
Vim's :s command normally replaces matches with a literal string.
command-line #search #editing #ex-commands #command-line #registers
n.
The n.
:let @/ = "pattern"
Assigning a string directly to the search register @/ with :let causes Vim to highlight all matches (if hlsearch is enabled) without performing a search or movi
\@<= and \@=
Vim's regex engine supports zero-width lookahead and lookbehind assertions using the \@ atom.
:s/pattern/\=expr/
Prefixing the replacement field of :s with \= makes Vim evaluate the rest as a Vimscript expression and use the result as the replacement string.
\@=
Vim's regex engine supports zero-width lookahead and lookbehind assertions using the \@ family of atoms.