neocomplete.vim
今天介绍两个个必备的vim插件,自动补全插件——neocomplete.vim和superTab。
neocomplete.vim是来自shougo的作品。该插件维护了当前buffer的一个关键词列表,从而提供强大的关键词补全功能。
该插件是他前作neocomplcache的升级版,速度更快,功能更强大。不过该插件需要if_lua的支持。
mac下安装:
brew install macvim --with-cscope --with-lua --HEAD
或者不用macvim(真的不用么?赶紧试试吧):
brew install vim --with-lua
不需要过多的介绍,看作者给的图:
文件补全
Omni 补全
Vim 补全
作者还给出了推荐配置,每个配置都有对应的英文注释,我就不一一翻译了:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
| "Note: This option must set it in .vimrc(_vimrc). NOT IN .gvimrc(_gvimrc)!
" Disable AutoComplPop.
let g:acp_enableAtStartup = 0
" Use neocomplete.
let g:neocomplete#enable_at_startup = 1
" Use smartcase.
let g:neocomplete#enable_smart_case = 1
" Set minimum syntax keyword length.
let g:neocomplete#sources#syntax#min_keyword_length = 3
let g:neocomplete#lock_buffer_name_pattern = '\*ku\*'
" Define dictionary.
let g:neocomplete#sources#dictionary#dictionaries = {
\ 'default' : '',
\ 'vimshell' : $HOME.'/.vimshell_hist',
\ 'scheme' : $HOME.'/.gosh_completions'
\ }
" Define keyword.
if !exists('g:neocomplete#keyword_patterns')
let g:neocomplete#keyword_patterns = {}
endif
let g:neocomplete#keyword_patterns['default'] = '\h\w*'
" Plugin key-mappings.
inoremap <expr><C-g> neocomplete#undo_completion()
inoremap <expr><C-l> neocomplete#complete_common_string()
" Recommended key-mappings.
" : close popup and save indent.
inoremap <silent> <CR> <C-r>=<SID>my_cr_function()<CR>
function! s:my_cr_function()
return neocomplete#close_popup() . "\"
" For no inserting key.
"return pumvisible() ? neocomplete#close_popup() : "\"
endfunction
" : completion.
inoremap <expr><TAB> pumvisible() ? "\" : "\"
" , : close popup and delete backword char.
inoremap <expr><C-h> neocomplete#smart_close_popup()."\"
inoremap <expr><BS> neocomplete#smart_close_popup()."\"
inoremap <expr><C-y> neocomplete#close_popup()
inoremap <expr><C-e> neocomplete#cancel_popup()
" Close popup by .
"inoremap pumvisible() ? neocomplete#close_popup() : "\"
" For cursor moving in insert mode(Not recommended)
"inoremap neocomplete#close_popup() . "\"
"inoremap neocomplete#close_popup() . "\"
"inoremap neocomplete#close_popup() . "\"
"inoremap neocomplete#close_popup() . "\"
" Or set this.
"let g:neocomplete#enable_cursor_hold_i = 1
" Or set this.
"let g:neocomplete#enable_insert_char_pre = 1
" AutoComplPop like behavior.
"let g:neocomplete#enable_auto_select = 1
" Shell like behavior(not recommended).
"set completeopt+=longest
"let g:neocomplete#enable_auto_select = 1
"let g:neocomplete#disable_auto_complete = 1
"inoremap pumvisible() ? "\" : "\\"
" Enable omni completion.
autocmd FileType css setlocal omnifunc=csscomplete#CompleteCSS
autocmd FileType html,markdown setlocal omnifunc=htmlcomplete#CompleteTags
autocmd FileType javascript setlocal omnifunc=javascriptcomplete#CompleteJS
autocmd FileType python setlocal omnifunc=pythoncomplete#Complete
autocmd FileType xml setlocal omnifunc=xmlcomplete#CompleteTags
" Enable heavy omni completion.
if !exists('g:neocomplete#sources#omni#input_patterns')
let g:neocomplete#sources#omni#input_patterns = {}
endif
"let g:neocomplete#sources#omni#input_patterns.php = '[^. \t]->\h\w*\|\h\w*::'
"let g:neocomplete#sources#omni#input_patterns.c = '[^.[:digit:] *\t]\%(\.\|->\)'
"let g:neocomplete#sources#omni#input_patterns.cpp = '[^.[:digit:] *\t]\%(\.\|->\)\|\h\w*::'
" For perlomni.vim setting.
" https://github.com/c9s/perlomni.vim
let g:neocomplete#sources#omni#input_patterns.perl = '\h\w*->\h\w*\|\h\w*::'
|
没有特殊需求,直接copy就用即可。没有复杂的配置,用起来还是非常简单的。
还有一个比较出名的补全插件是YouCompleteMe.大家也可以去看下,应该是现在用的最广泛的补全插件了。我很早就试用过,还是neocomplete要更顺手更快些,总感觉neocomplete要更智能些。
superTab
说到补全还有个不得不说,那就是tab键,必须用tab来进行补全那才是补全啊。其实neocomplete的推荐配置已经配置成了自动提示补全文字,并且支持tab选择,但是还是无法shift-tab
回退选择。superTab就是为增强tab而生,当然可以做到这点。
superTab 和neocomplete一样,几乎不用自己折腾什么配置,也不用过多的介绍,一句话就可以说完它的功能。
bar
baz
b* (*为光标所在位置)
按示例在光标处按下tab,就会展开推荐补全bar和baz,按tab即可进行循环选择。
可以配置supertab的默认补全类型(对vim补全不了解的同学自己补下omni补全相关知识,需要我介绍可以回复下):
let g:SuperTabDefaultCompletionType = ""
示例把supertab修改为了用户补全,默认是
.
今天就介绍到这里。