Ⅰ. 插件描述
A simple context-based vim completion plugin.Ⅱ. 基本信息
|
Ⅲ. 安装方法
使用Vundle管理器安装
在你的.vimrc下添加:Plugin 'leafoftree/vim-imagine'
… 然后在Vim中运行以下命令:
:source %
:PluginInstall
对于Vundle版本 < 0.10.2,请用上面的Bundle替换Plugin。
使用NeoBundle管理器安装
在你的.vimrc下添加:NeoBundle 'leafoftree/vim-imagine'
… 然后在Vim中运行以下命令:
:source %
:NeoBundleInstall
使用VimPlug管理器安装
在你的.vimrc下添加:Plug 'leafoftree/vim-imagine'
… 然后在Vim中运行以下命令:
:source %
:PlugInstall
使用Pathogen管理器安装
在终端中运行以下命令:cd ~/.vim/bundle
git clone https://github.com/leafoftree/vim-imagine
Ⅳ. 文档说明
# vim-imagine
A simple context-based vim completion plugin. It wil try to return the most possible word based on current context. Choosing a word from the menu should be avoided.
Supports
- Literial tab.
- Custom snippets.
- Extensible fuzzy match.
- emmet-vim.
- supertab.
Usage
In INSERT mode, press tab to complete the word. Press c-u to undo the completion.
Install
- Use VundleVim:
Plugin 'leafOfTree/vim-imagine'
- Or manually, clone this plugin, drop it in custom
path/to/this_plugin
, and add it tortp
in vimrcset rpt+=path/to/this_plugin
How it works
It tries these methods in order to find out the completion word.
- Literial tab.
- Custom snippets.
- Extensible fuzzy match.
- emmet-vim.
- supertab.
Literial tab
It will return literial tab if there are blanks or the start of line before the cursor.
Custom snippets
It will return the snippet if the characters before the cursor match the key in the dictionary defined by snippets file.
Extensible fuzzy search
It returns the first match that fuzzy methods find in current file. The order can be changed by g:vim_imagine_fuzzy_chain except the favoured
method.
The longest is used if there are more than one matched words.
The fuuzy search will try lines near current line first, then all the lines. See fuzzy_near.
Builtin methods
favoured(Always try it at first)
If [g:vim_imagine_fuzzy_favoured_words](#fuzzy_favoured_words) is `['myLongName', 'anotherLongName']`,
mln -> myLongName
- hyphen
adg -> abc-def-ghi
- capital
adg -> abcDefGhi
dot
adg -> abc.def.ghi
**Note**: context words won't be split by `.` in this method
- underscore
adg -> abc_def_ghi
- include
xyz -> 000x111y222z
Custom methods
All methods defined in g:vim_imagine_fuzzy_custom_methods are used in fuzzy completion. See the example.
Emmet
It will return emmet-vim's result if it's installed when there is only one character before the cursor or b:vim_imagine_use_emmet is 1.
Supertab
It will return supertab's result if it's installed. It's worth nothing that tab can't be used to move in popup menu, but up, down, enter still work.
Configuration
Variables
g:vim_imagine_snippets_path
- description: the path of the snippets file under the
runtimepath
. See the example snippets - type:
string
. - default:
'plugin/imagine_snippets.vim'
.
It's recommended to put it under .vim
or vimfiles
. It's a normal vimscript file. The only requirement is that these dictionary variables g:vim_imagine_dict
,g:vim_imagine_dict_1
,g:vim_imagine_dict_2
are defined as expected. If the path is not readable, the example snippets will be used.
Snippets file format
For dictionary variableg:vim_imagine_dict
,g:vim_imagine_dict_1
,g:vim_imagine_dict_2
, the key is the chars before the cursor, and the value is the snippet string.
Special characters like \r
, \t
, \e
are supported in double quoted string(see :h string
). Normal mode commands can be executed after \e
.
|
can be used to mark cursor location.
g:vim_imagine_fuzzy_chain
- description: the order of methods that fuzzy search uses.
- type:
list
. default:
let g:vim_imagine_fuzzy_chain = [ \'capital', \'dot', \'hyphen', \'underscore', \'include', \]
g:vim_imagine_fuzzy_near
- description: the top and bottom offset to current line which defines the lines to search first.
- type:
list
. default:
let g:vim_imagine_fuzzy_near = [5, 0]
g:vim_imagine_fuzzy_near_chain
- description: the order of methods that fuzzy near search uses.
- type:
list
. default:
let g:vim_imagine_fuzzy_chain = [ \'capital', \'dot', \'hyphen', \'underscore', \'include', \]
g:vim_imagine_fuzzy_custom_methods
- description: defines custom methods that fuzzy search uses.
type:
dictionary
.- members:
chars => regexp
. Thechars
is the characters before the cursor and theregexp
is used to match words in current file. The member name can be used ing:vim_imagine_fuzzy_chain
. members end with
_splits
:splits => modified splits
. Modifysplits
which determines how words is generated from current file. Default is a comma-separated string(comma and space will always be added).(,),{,},<,>,[,],=,:,'',",;,/,\,+,!,#,*,`,|,.
- members:
- default:
{}
let g:vim_imagine_fuzzy_custom_methods = {} function! g:vim_imagine_fuzzy_custom_methods.same_first(chars) let case_flag = '' if a:chars =~ '\v\C[A-Z]' let case_flag = '\C' endif let regexp = join(split(a:chars, '\zs'), '.*') let regexp = escape(regexp, '()@$') let regexp = '\v'.case_flag.'^(\@|\$)?'.regexp.'.*>' return regexp endfunction let g:vim_imagine_fuzzy_chain = [ \'capital', \'hyphen', \'dot', \'underscore', \'same_first', \'include', \]
g:vim_imagine_fuzzy_favoured_words
- description: The words to check firstly when fuzzy search starts. The list can be changed while editing files by leader a in NORMAL mode.
- type:
list
. - default:
[]
b:vim_imagine_use_emmet
- description: Enable emmet method at first. It can be togggled by c-f.
- type:
int
(0 or 1) - default:
0
example:
autocmd FileType html,pug,xml,css,less let b:vim_imagine_use_emmet = 1
Mappings
INSERT mode
- tab: complete the chars before the cursor.
c-u: undo the completion.
let g:vim_imagine_mapping_undo_completion = '<c-u>'
c-f: toggle emmet.
let g:vim_imagine_mapping_toggle_emmet = '<c-f>'