swap parameters


Ⅰ. 插件描述

swap parameters of a function (requires python)

Ⅱ. 基本信息

创建日期:  2007-09-28
使用用户:  18
Github星:  6
插件作者:  Kamil Dworakowski

Ⅲ. 安装方法

使用Vundle管理器安装

在你的.vimrc下添加:
Plugin '/swap-parameters'
… 然后在Vim中运行以下命令:
:source %
:PluginInstall

对于Vundle版本 < 0.10.2,请用上面的Bundle替换Plugin。

使用NeoBundle管理器安装

在你的.vimrc下添加:
NeoBundle '/swap-parameters'
… 然后在Vim中运行以下命令:
:source %
:NeoBundleInstall

使用VimPlug管理器安装

在你的.vimrc下添加:
Plug '/swap-parameters'
… 然后在Vim中运行以下命令:
:source %
:PlugInstall

使用Pathogen管理器安装

在终端中运行以下命令:
cd ~/.vim/bundle
git clone https://github.com/vim-scripts/swap-parameters

Ⅳ. 文档说明

Requires python and Vim compiled with +python option

Basic Usecase: Place the cursor inside the parameter you want to swap
with the next one, and press gs

It is a versatile script to swap parameters of a function
or, generally speaking, elements in any coma seperated list.

key bindings (normal mode):
[count]gs -- where count defaults to 1 -- swap the argument under
             the cursor with the [count] next one
[count]gS -- swap with the previous one

Below are exaples of what happens after pressing gs (equivalent to 1gs).
Prettier version can be found here:
http://blog.kamil.dworakowski.name/2007/09/swap-parameters-script-for-vim.html.
On each line the lefthand side shows the line before typing gs, and
the righthand 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|)|]

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(par|m|1[], parm2) ==> 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)

A useful, however unexpected by the author, feature of this script is that
on pressing j to move cursor to the line below, the cursor is restored to
the column position before the swap. This allows for a streamlined
swaping of parameters in the case like this:

fun(arg2, arg1)
fun(arg2, arg1)
fun(arg2, arg1)

You would put cursor on arg2, and type gsjgsjgs

添加新评论