Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to efficiently switch arguments in vim

Tags:

vim

I come upon one scenario when editing a file in vim and I still haven't found a way to do it quickly in vim way. When editing a call of a function, I offently put my arguments in a wrong order.

anyFunction(arg2, arg1)

When arriving on this situation, I have to find arg2 / delete it / append it before the ')' / deal with the ', ' / etc.

Isn't it a better way to this task quickly ? I am open to any idea (macro/ shortcut / plugin) even if I'd rather have a 'vim only' way of doing this

like image 308
Raphael Pr Avatar asked Dec 19 '22 13:12

Raphael Pr


1 Answers

You need two things:

  1. A text object to quickly select an argument (as they aren't always that simple like in your example). argtextobj plugin (my improved fork here) does this.
  2. Though you can use delete + visual mode + paste + go back + paste, a plugin to swap text makes this much easier. My SwapText plugin or the already mentioned exchange plugin both do that job.
like image 194
Ingo Karkat Avatar answered Jan 15 '23 19:01

Ingo Karkat