_____ ____ __ / ___/_ ______ _____ / __ \____ __________ _____ ___ ___ / /____ __________ \__ \| | /| / / __ `/ __ \ / /_/ / __ `/ ___/ __ `/ __ `__ \/ _ \/ __/ _ \/ ___/ ___/ ___/ /| |/ |/ / /_/ / /_/ / / ____/ /_/ / / / /_/ / / / / / / __/ /_/ __/ / (__ ) /____/ |__/|__/\__,_/ .___/ /_/ \__,_/_/ \__,_/_/ /_/ /_/\___/\__/\___/_/ /____/ /_/
Swap parameters of a function with a single command.
In normal mode, these key commands will swap parameters:
[count]gs
Swap the parameter under the cursor with the next one.[count]gS
Swap the current parameter with the previous parameter.
Note: [count]
defaults to 1
.
- Add
Bundle 'mutewinter/swap-parameters'
to your.vimrc
file. - Restart Vim.
- Now run
:BundleInstall
. - Enjoy.
Below are examples of what happens after pressing gs (equivalent to 1gs). On each line the left side shows the line before typing gs, and the right side shows the effect. The cursor position is depicted with || symbols. par|m|1 means that the cursor is on the character m.
fun(par|m|1, parm2) fun(parm2, parm|1|) fun(par|m|1(), parm2) fun(parm2, parm1(|)|) fun(parm1(|)|, parm2) fun(parm2, parm1(|)|) fun(parm|1|(arg,arg2), parm2) fun(parm2, parm1(arg,arg2|)|) fun(parm1|(|arg,arg2), parm2) fun(parm2, parm1(arg,arg2|)|) fun(parm1(arg,arg2|)|, parm2) fun(parm2, parm1(arg,arg2|)|) fun(parm1(arg, arg2|)|, parm2) fun(parm2, parm1(arg, arg2|)|) fun(arg1, ar|g|2, arg3) fun(arg1, arg3, arg|2|) array[a|r|g1, arg2] array[arg2, arg|1|] fun(par|m|1[], parm2) fun(parm2, parm1[|]|) fun(parm1[|]|, parm2) fun(parm2, parm1[|]|) fun(par|m|1, array[]) fun(array[], parm|1|) fun(|a|,b) fun(b,|a|) [(p1, p2|)|, p3] [p3, (p1, p2|)|] for |a|, b in some_dict.items() for b, |a| in some_dict.items()
The following lines demonstrate using gS (swap with previous).
fun(parm2, par|m|1) fun(|p|arm1, parm2) fun(parm2, par|m|1()) fun(|p|arm1(), parm2) fun(parm2, parm1(|)|) fun(|p|arm1(), parm2) fun(parm2, parm|1|(arg,arg2)) fun(|p|arm1(arg,arg2), parm2) fun(parm2, parm1|(|arg,arg2)) fun(|p|arm1(arg,arg2), parm2) fun(parm2, parm1(arg,arg2|)|) fun(|p|arm1(arg,arg2), parm2) fun(parm2, parm1(arg, arg2|)|) fun(|p|arm1(arg, arg2), parm2) fun(arg1, ar|g|2, arg3) fun(|a|rg2, arg1, arg3) fun(arg1, arg2, ar|g|3) fun(arg1, |a|rg3, arg2) array[arg2, a|r|g1] array[|a|rg1, arg2] fun(parm2, par|m|1[]) fun(|p|arm1[], parm2) fun(parm2, parm1[|]|) fun(|p|arm1[], parm2) fun(array[], par|m|1) fun(|p|arm1, array[]) fun(b,|a|) fun(|a|,b) for a, |b| in some_dict.items() for |b|, a in some_dict.items()
The above examples are auto-generated from the tests.
Dot repeats don't work with this binding but pressing gs is quick enough I think.
The column position of the cursor is preserved when you go to the next line after swap. This allows for streamlined swapping of parameters in the case like this:
fun(arg2, blah) fun(arg2, blahble) fun(arg2, blahblahblah)
You would put cursor on arg2, and the gsjgsjgs
This script is written in python. Therefore it needs Vim compiled with +python option (:version), as well as Python installed in the system.
Author | Kamil Dworakowski <kamil-at-dworakowski.name> |
---|---|
Updated By | Jeremy Mack @mutewinter |
Version | 1.2.0 |
Last Change | 2012-05-10 |
URL | https://github.com/mutewinter/swap-parameters |
Requires | Python and Vim compiled with +python option |
Licence | MIT Licence |