How to jump to the matching bracket in Vim
Put the cursor on a bracket, (, [ or {, and press % in Normal mode to jump to its partner. Press % again to jump back.
Drop the debug options
The cursor is on a comma, not a bracket. d% still works: % finds the next bracket on the line, the {, so d% deletes from the comma to its }. Then do the same on the next line, with . to repeat it.
This editor needs a keyboard. Read on, and play it at your computer.
| Keys | What it does |
|---|---|
| % on a bracket | Jumps to its partner: ( and ), [ and ], { and }, across lines too. |
| % off a bracket | Finds the first bracket after the cursor on the same line and jumps to that one's partner. |
| d% | Deletes from the cursor to the partner, both brackets included. |
| v% / y% / c% | Selects / copies / changes the same stretch. |
| [( / [{ | Goes back to the ( or { that the cursor is inside. |
| ]) / ]} | Goes forward to the ) or } that closes it. |
| 50% | With a count, % means a percentage: halfway down the file. |
:set matchpairs+=<:> ↵ | Adds < and > to the pairs that % knows. |
Inside a block, not on its bracket
% needs a bracket on the cursor's line. When you are somewhere inside a long block, [{ goes back to the { that opens it and ]} forward to the } that closes it; [( and ]) do the same for parentheses. They skip pairs that are already closed, so from anywhere in a function body [{ finds the function's opening brace, then % takes you to its end.
To act on the whole contents rather than travel, text objects are often shorter: di( deletes everything inside the parentheses around the cursor, and da{ deletes the braces too.
HTML tags, if and else: matchit
Out of the box, % matches brackets (and C comments and #if/#endif). The matchit plugin teaches it more pairs, defined per language by the filetype plugin: an HTML opening tag and its closing tag, if, else and fi in shell scripts, if and endif in Vim script. Neovim loads matchit by default. Vim ships it as an optional package: add packadd! matchit to ~/.vimrc, with filetype plugin on so the pairs are defined.