Learn Vim / How to Delete Everything Inside Parentheses in Vim

How to Delete Everything Inside Parentheses in Vim

The answerWith the cursor inside (or on) the parentheses, press di( — delete inside parens.

Try it on a real buffer

Those arguments have to go. Jump to the opening paren with f(, then press di( to delete everything inside them.

result = calculate(all, of, these, args, must, go)

Canonical solution: f( di( · target: 5 keystrokes — the fewest that solve it (every keypress counts).

Why it works

f{char} jumps forward to the next {char} on the line (; repeats the jump, F goes backward). di( / di) deletes inside the nearest enclosing parens.

Variations

KeysWhat it does
di(delete inside ( )
da(delete the parentheses too
ci(delete inside and enter insert mode
di{ di[ ditsame for braces, brackets, HTML tags
▶ live vim buffertarget 5 keystrokes
Those arguments have to go. Jump to the opening paren with f(, then press di( to delete everything inside them.

Reading about keystrokes doesn't build keystrokes. Try this in a real vim buffer right now — the “Empty the call” mission takes about a minute.

Sign in free to practice →

Keep going