navigation
%
In normal mode, % jumps between matching pairs of (), [], {}, and (with matchit) HTML/XML tags. Indispensable for navigating nested code and confirming that a stray brace really does close where you think it does.
% (normal / visual mode) Variations
| Keystroke | Effect |
|---|---|
| d% | Delete from opening bracket to matching close (or vice versa) |
| y% | Yank the enclosed region including brackets |
| v% | Visually select from bracket to its match |
| { / } | Related paragraph motion — jump to previous / next blank line |
Examples
% With cursor on {, jump to the matching }
d% Delete an entire (…) expression including both parens
V% Line-select an entire function body defined by { }
Gotcha
Cursor must be ON the bracket, not just near it. Note: % in :substitute means 'whole file' — same character, totally different meaning.
Related
:s and :%s
Substitute (find-and-replace) within a range of lines. Without a range :s works on the current line only; :%s uses % as shorthand for the whole file (equivalent to :1,$s). Add flags like g (all matches per line) and c (confirm).
gg / G
gg jumps to the first line of the file; G jumps to the last line. Prefix G with a number to jump to that absolute line — the fastest way to reach a specific line from a stack trace.
w / b / e
Word motions: w jumps to the start of the next word, b to the start of the previous word, e to the end of the current/next word. These are the fastest way to hop across a line without leaving the home row.
h j k l
The four fundamental cursor keys in Vim: h moves left, j down, k up, l right. Reach for them any time you would instinctively hit an arrow key — keeping your hands on the home row is the whole point.
0 / $
0 jumps to the very first column of the line; $ jumps to the last character. Use ^ (bonus) if you want the first non-blank character instead of column zero.