What is the most efficient way to swap two params for a method call in Vim?
For example, I want to change:
call "hello mister 123", 2343
call 2343, "hello mister 123"
(Assume the cursor is at the beginning of the line.)
Ideally the trick works for stuff like
call "hello, world" , "goodbye, world"
This regex will do it for your examples:
This regex will need to become progressively more nasty if you have escaped quotation marks and such things in one of your parameters.
In reality, I'd just highlight one parameter (in visual mode), hit
d, highlight the other parameter, and hit
p; Vim will nicely paste what's in the register, overwriting what you have highlighted, and swap the deleted text into the register. Then move the cursor and hit
p, move cursor,
pis a common combination, in my vimming at least.
So with the cursor at the start of the line, first example:
Meaning move past the word "call" (
w), highlight a quoted string (
va"), delete it (
d), move one space to the right (
l), highlight a word (
vaw), paste (
p), move backward to the comma (
F,), paste before it (
This isn't hard once you get used to the movement commands.