The fastest way to remove a function argument in Vim

If I have the following code:

foo->call(bar, baz->widget); 

Using the cursor "b" in "baz" or "w" in "widgets", how would I quickly remove an argument in the cursor?

 foo->call(bar); 

This can be any argument (first, last or in the middle).

+7
source share
5 answers

With my omap-param plugin , just type di, or da, ,.

This will not bother other brackets. For example, in f(a+g(42, "string")), foobar) , from "a" to "g", da, will simply leave foobar in the f call.

+10
source

For the first argument, this key combination goes into the opening bracket and removes everything until the next comma, including a space after it:

T(df,x

For the middle argument, this key combination goes to the previous comma and deletes it and everything to the next comma:

F,dt,

For the last argument, this key combination goes to the previous comma and removes it and everything to the closing parenthesis:

F,dt)

-- or --

You can write your own macro for this kind of thing. A similar example is here .

+6
source

vim-argumentative is another plugin option that provides text objects a, and i, and more.

+2
source

targets.vim is an optional plugin that provides aa and ia (which also fixes the default behavior of inline text objects, compare the discussion of TextObjectify )

+2
source

?, enter to go to the previous ','

d /, enter to delete until next ','

no plugins required

you may need to add a number to your search terms in case of template parameters:

void foo (sometype a, some_template_type <sometype, sometype> b, sometype c)

or you can click "." no matter how many comma separations you want to get rid of.

0
source

All Articles