Ⅰ. 插件描述
Move function arguments (and other delimited-by-something items) left and rightⅡ. 基本信息
|
Ⅲ. 安装方法
使用Vundle管理器安装
在你的.vimrc下添加:Plugin '/sideways-vim-thing-itself'
… 然后在Vim中运行以下命令:
:source %
:PluginInstall
对于Vundle版本 < 0.10.2,请用上面的Bundle替换Plugin。
使用NeoBundle管理器安装
在你的.vimrc下添加:NeoBundle '/sideways-vim-thing-itself'
… 然后在Vim中运行以下命令:
:source %
:NeoBundleInstall
使用VimPlug管理器安装
在你的.vimrc下添加:Plug '/sideways-vim-thing-itself'
… 然后在Vim中运行以下命令:
:source %
:PlugInstall
使用Pathogen管理器安装
在终端中运行以下命令:cd ~/.vim/bundle
git clone https://github.com/vim-scripts/sideways.vim
Ⅳ. 文档说明
Github project: https://github.com/AndrewRadev/sideways.vim
The plugin defines two commands, ":SidewaysLeft" and ":SidewaysRight", which move the item under the cursor left or right, where an "item" is defined by a delimiter. As an example:
def function(one, two, three):
pass
Placing the cursor on "two" and executing :SidewaysLeft, the "one" and "two" arguments will switch their places, resulting in this:
def function(two, one, three):
pass
In this case, the delimiter is a comma. The plugin currently works with various other cases and it's intended to make the process configurable. While this particular example is in python, this should work for arguments in many different languages that use round braces to denote function calls.
For ruby and eruby, it detects method calls without braces as well:
link_to user_registration_path, 'Something'
# changes to:
link_to 'Something', user_registration_path
Apart from functions, it works for square-bracket lists in dynamic languages:
list = [one, [two, four, five], three]
Notice that, if you experiment with this example, you'll find that you can move the entire second list around. The plugin takes into consideration nested structures.
It also works for multiline lists. Try experimenting with this example:
<div class="example"
style="color: red;"
something="other">
Example
</div>
Apart from functions, it works for lists in CSS declarations:
border-radius: 20px 0 0 20px;
And, it also works for cucumber tables (see docs for better table formatting):
Examples:
| input_1 | input_2 | button | output |
| 20 | 30 | add | 50 |
| 2 | 5 | add | 7 |
| 0 | 40 | add | 40 |
It's highly suggested to map the two commands to convenient keys. For example, mapping them to <c-h> and <c-l> would look like this:
nnoremap <c-h> :SidewaysLeft<cr>
nnoremap <c-l> :SidewaysRight<cr>
The plugin is intended to be customizable, though at this point you'd need to look at the source to do this.