Ⅰ. 插件描述
More useful word motions for VimⅡ. 基本信息
|
Ⅲ. 安装方法
使用Vundle管理器安装
在你的.vimrc下添加:Plugin 'chaoren/wordmotion-vim'
… 然后在Vim中运行以下命令:
:source %
:PluginInstall
对于Vundle版本 < 0.10.2,请用上面的Bundle替换Plugin。
使用NeoBundle管理器安装
在你的.vimrc下添加:NeoBundle 'chaoren/wordmotion-vim'
… 然后在Vim中运行以下命令:
:source %
:NeoBundleInstall
使用VimPlug管理器安装
在你的.vimrc下添加:Plug 'chaoren/wordmotion-vim'
… 然后在Vim中运行以下命令:
:source %
:PlugInstall
使用Pathogen管理器安装
在终端中运行以下命令:cd ~/.vim/bundle
git clone https://github.com/chaoren/vim-wordmotion
Ⅳ. 文档说明
More useful word motions for Vim
Under Vim's definition of a word:
CamelCaseACRONYMWords_underscore1234
w--------------------------------->w
e--------------------------------->e
b<---------------------------------bWith this plugin:
CamelCaseACRONYMWords_underscore1234
w--->w-->w----->w---->w-------->w->w
e-->e-->e----->e--->e--------->e-->e
b<---b<--b<-----b<----b<--------b<-bword definitions
word | Example |
|---|---|
| Camel case words | [Camel][Case] |
| Acronyms | [HTML]And[CSS] |
| Uppercase words | [UPPERCASE] [WORDS] |
| Lowercase words | [lowercase] [words] |
| Hexadecimal literals | [0x00ffFF] [0x0f] |
| Octal literals | [0o644] [0o0755] |
| Binary literals | [0b01] [0b0011] |
| Regular numbers | [1234] [5678] |
| Other characters | [~!@#$] |
Customization
The default word motion mappings are as follows:
| Mode | Mapping |
|---|---|
nxo | w |
nxo | b |
nxo | e |
nxo | ge |
xo | aw |
xo | iw |
c | <C-R><C-W> |
Use g:wordmotion_prefix to apply a common prefix to each of the default word
motion mappings.
E.g.,
let g:wordmotion_prefix = '<Leader>'NOTE: does not apply to the command line mode <C-R><C-W> mapping.
Use g:wordmotion_mappings to individually replace the default word motion
- E.g.,
let g:wordmotion_mappings = {
\ 'w' : '<M-w>',
\ 'b' : '<M-b>',
\ 'e' : '<M-e>',
\ 'ge' : 'g<M-e>',
\ 'aw' : 'a<M-w>',
\ 'iw' : 'i<M-w>',
\ '<C-R><C-W>' : '<C-R><M-w>'
\ }Unspecified entries will still use the default mappings.
Set the value to an empty string to disable the mapping.
NOTE: this overrides g:wordmotion_prefix.
Use g:wordmotion_spaces (default '_') to designate extra space characters.
E.g.,
let g:wordmotion_spaces = '_-.'will produce the following result:
foo_bar-baz.qux
w-->w-->w-->w>wAll options can be applied dynamically by reloading the plugin.
E.g., to disable the w mapping:
let g:wordmotion_mappings['w'] = ''
unlet g:loaded_wordmotion
runtime plugin/wordmotion.vimthen later re-enable it
let g:wordmotion_mappings['w'] = '<M-w>'
unlet g:loaded_wordmotion
runtime plugin/wordmotion.vimCaveats
There are some special cases with how Vim's word motions work.
E.g.,
Vim:
^foo [b]ar$ -> dw -> ^foo[ ]$
^ baz$ ^ baz$
^[f]oo bar$ -> cw -> ^[ ]bar$
This plugin:
^foo [b]ar$ -> dw -> ^foo [b]az$
^ baz$
^[f]oo bar$ -> cw -> ^[b]ar$This plugin faithfully follows the motion of w when executing dw and cw,
while Vim replaces these two special cases with the behavior of de and ce,
respectively.
If you want to restore Vim's special case behavior with dw and cw, you can
do this:
nmap dw de
nmap cw ceIf you want to also remove the special case behavior from dW and cW, as this
plugin does with dw and cw, you can do this:
onoremap W :<C-U>normal! vWh<CR>