How do I search for a pattern that spans multiple lines?
/pattern1\_.*pattern2
Vim's \ modifier makes any character class match newlines too.
/pattern1\_.*pattern2
Vim's \ modifier makes any character class match newlines too.
"1p ... "2p ... "9p
Vim maintains a numbered register history from "1 through "9 that stores your last 9 deletes and changes.
( / ) / { / }
Vim treats sentences and paragraphs as first-class navigation units.
navigation #navigation #motions #text-objects #prose #editing
:make
The :make command runs your build tool and parses its output into the quickfix list, letting you jump directly to each error location.
command-line #command-line #quickfix #build #workflow #programming
:set foldmethod=marker
Setting foldmethod=marker lets you define fold boundaries using special comment markers — {{{ to start a fold and }}} to end it.
:'a,'b s/old/new/g
Marks can be used as range specifiers in any Ex command.
command-line #marks #command-line #ex-commands #ranges #editing
gJ
The gJ command joins the current line with the line below it without inserting any space between them.
% with matchit plugin
The % command jumps between matching brackets by default, but with the built-in matchit plugin, it extends to match language-specific keywords like if/else/endi
:g/pattern/y A
The :g/pattern/y A command yanks every line matching the pattern and appends it to register a.
command-line #command-line #registers #global #ex-commands #filtering
<C-a> / <C-x>
Pressing increments and decrements the number under or after the cursor.
ga
The ga command displays the ASCII/Unicode value of the character under the cursor in decimal, hexadecimal, and octal.
editing #editing #unicode #debugging #normal-mode #inspection
:set foldmethod=indent
Setting foldmethod=indent tells Vim to create folds based on the indentation level of each line.
:g/pattern/normal @q
The :global command combined with :normal lets you execute a recorded macro on every line that matches a given pattern.
macros #macros #command-line #ex-commands #global #batch-editing
:g/pattern/m$
The :g (global) command combined with :m (move) relocates all matching lines to a specified destination.
command-line #command-line #ex-commands #global #editing #organization
:X
The :X command sets an encryption key for the current file.
command-line #command-line #security #file-management #ex-commands
:'<,'>normal A;
The :normal command executes normal-mode keystrokes on every line in a range.
command-line #command-line #ex-commands #editing #normal-mode #batch-editing
!{motion}command
The ! operator in normal mode pipes text through an external shell command and replaces it with the output.
ci" / ci( / ci{ / ci[ / ci` / ci'
The ci{delimiter} family of commands changes the text inside any matching pair of delimiters.
editing #editing #text-objects #change #delimiters #normal-mode
d2i(
Vim text objects accept a count prefix that lets you target outer layers of nested delimiters.
onoremap ih :<C-u>execute "normal! ?^==\+$\r:noh\rkvg_"<CR>
Vim lets you define custom text objects using operator-pending mode mappings (onoremap) and visual mode mappings (vnoremap).