swap-parameters


Ⅰ. 插件描述

Swap parameters of a function or a comma separated list with a single command.

Ⅱ. 基本信息

创建日期:  2007-09-28
使用用户:  18
Github星:  2
插件作者:  Jeremy Mack

Ⅲ. 安装方法

使用Vundle管理器安装

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

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

使用NeoBundle管理器安装

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

使用VimPlug管理器安装

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

使用Pathogen管理器安装

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

Ⅳ. 文档说明

# Alert: Better Plugin Exists

Just use vim-swap it's so much better. It even has an interactive mode.

Description

Swap parameters of a function or a comma separated list with a single command.

Usage

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.

Installation

_Note: Requires vim compiled with python support. To check if you have python
support, run vim --version | grep python and see if it says +python._

Vundle

  1. Add Bundle 'mutewinter/swap-parameters' to your .vimrc file.
  2. Restart Vim.
  3. Now run :BundleInstall.
  4. Enjoy.

Customization

You can change mappings by using the g:SwapParametersMapForwards and
g:SwapParametersMapBackwards variables:

g:SwapParametersMapForwards = '<leader>s'
g:SwapParametersMapBackwards = '<leader>S'

Examples

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.

About

AuthorKamil Dworakowski <kamil-at-dworakowski.name>
Updated ByJeremy Mack @mutewinter
Version1.2.1
Last Change2012-09-06
URLhttps://github.com/mutewinter/swap-parameters
RequiresPython and Vim compiled with +python option
LicenceMIT Licence

添加新评论