vimtricks.wiki Concise Vim tricks, one at a time.

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.vim also provides in( (next inner parens) and il( (last inner parens)
  • Neovim's Treesitter textobjects provide @parameter.inner as an alternative
  • For vanilla Vim, f,dt, or T,ct, can delete between commas manually

Next

How do I return to normal mode from absolutely any mode in Vim?