How do I select, change, or delete function arguments as text objects?
Answer
cia (with targets.vim) or daa
Explanation
While Vim doesn't have a built-in argument text object, the targets.vim plugin adds ia (inner argument) and aa (around argument) text objects that understand comma-separated values in function calls, making argument manipulation effortless.
How it works
cia— change inner argument (content between commas/parens)daa— delete around argument (including trailing/leading comma)via— visually select inner argument- Works with any comma-separated list inside parentheses, brackets, etc.
Example
Code: function(first, second, third)
Cursor on 'second':
cia → function(first, |, third) (ready to type new argument)
daa → function(first, third) (argument and comma removed)
Tips
- Without plugins, use
di,to approximate argument deletion in some cases targets.vimalso providesin((next inner parens) andil((last inner parens)- Neovim's Treesitter textobjects provide
@parameter.inneras an alternative - For vanilla Vim,
f,dt,orT,ct,can delete between commas manually