How do I quickly delete all the arguments inside a function call?
Answer
di(
Explanation
The di( command deletes everything inside the nearest pair of parentheses without removing the parentheses themselves. This is one of Vim's most practical text object commands for editing code — it lets you clear out function arguments, conditional expressions, or grouped sub-expressions in a single keystroke sequence.
How it works
dis the delete operatori(is the "inner parentheses" text object — it selects everything between the nearest(and), excluding the parens themselves- The cursor can be anywhere inside the parentheses — Vim finds the enclosing pair automatically
di)is identical todi(— both refer to the same text object
Example
Given the text with the cursor anywhere between the parentheses:
calculateTotal(price, quantity, tax)
Pressing di( removes all three arguments:
calculateTotal()
The parentheses remain intact with the cursor between them, ready for you to type new arguments.
This also works with nested parentheses — Vim selects the innermost enclosing pair:
result = outer(inner(a, b), c)
With the cursor on a, pressing di( deletes a, b:
result = outer(inner(), c)
Tips
- Use
ci(to delete the contents and enter insert mode — perfect for replacing arguments in one motion - Use
da(to delete the contents and the parentheses themselves - Use
yi(to yank (copy) the contents inside parentheses without deleting - Use
vi(to visually select the contents for inspection before acting - The same pattern works for other paired delimiters:
di[/di]for square bracketsdi{/di}for curly bracesdi</di>for angle bracketsdi"for double quotes,di'for single quotes
- Use
2di(ordi(from within nested parens, then.outside, to work outward through nesting levels - Combine with
.to repeat: afterdi(, move to another function call and press.to clear its arguments too