功能
neocomplete 为 vim 提供智能提示功能,将 vim 改造成强大的IDE,效果如下图。
安装
安装neocomplete 插件需要lua支持,并且vim版本大于Vim 7.3.885。
1. 环境检测
打开vim,输入 :version,查看版本与lua模块,若版本不符合,先升级版本;若vim中不支持lua,则需要
重新编译vim,可以参考 recompile vim with lua。
注意: +lua 表示支持lua, -lua表示不支持,需要重新编译。
2. 下载neocomplete
GitHub:https://github.com/Shougo/neocomplete.vim
CSDN:http://download.csdn.net/detail/spch2008/8828389
将autoload 文件夹置于 ~/.vim/autoload
将plugin 文件夹置于 ~/.vim/plugin
3. 启用neocomplete
在 ~/.vimrc 中,写入: let g:neocomplete#enable_at_startup = 1
至此,neocomplete配置完成。同时,作者提供了一份neocomplete的配置,
如果没有特殊需要,可以直接使用。
1 " Use neocomplete. 2 let g:neocomplete#enable_at_startup = 1 3 " Use smartcase. 4 let g:neocomplete#enable_smart_case = 1 5 " Set minimum syntax keyword length. 6 let g:neocomplete#sources#syntax#min_keyword_length = 3 7 let g:neocomplete#lock_buffer_name_pattern = '*ku*' 8 9 " Define dictionary. 10 let g:neocomplete#sources#dictionary#dictionaries = { 11 'default' : '', 12 'vimshell' : $HOME.'/.vimshell_hist', 13 'scheme' : $HOME.'/.gosh_completions' 14 } 15 16 " Define keyword. 17 if !exists('g:neocomplete#keyword_patterns') 18 let g:neocomplete#keyword_patterns = {} 19 endif 20 let g:neocomplete#keyword_patterns['default'] = 'hw*' 21 22 " Plugin key-mappings. 23 inoremap <expr><C-g> neocomplete#undo_completion() 24 inoremap <expr><C-l> neocomplete#complete_common_string() 25 26 " Recommended key-mappings. 27 " <CR>: close popup and save indent. 28 inoremap <silent> <CR> <C-r>=<SID>my_cr_function()<CR> 29 function! s:my_cr_function() 30 return neocomplete#close_popup() . "<CR>" 31 " For no inserting <CR> key. 32 "return pumvisible() ? neocomplete#close_popup() : "<CR>" 33 endfunction 34 " <TAB>: completion. 35 inoremap <expr><TAB> pumvisible() ? "<C-n>" : "<TAB>" 36 " <C-h>, <BS>: close popup and delete backword char. 37 inoremap <expr><C-h> neocomplete#smart_close_popup()."<C-h>" 38 inoremap <expr><BS> neocomplete#smart_close_popup()."<C-h>" 39 inoremap <expr><C-y> neocomplete#close_popup() 40 inoremap <expr><C-e> neocomplete#cancel_popup() 41 " Close popup by <Space>. 42 "inoremap <expr><Space> pumvisible() ? neocomplete#close_popup() : "<Space>" 43 44 " For cursor moving in insert mode(Not recommended) 45 "inoremap <expr><Left> neocomplete#close_popup() . "<Left>" 46 "inoremap <expr><Right> neocomplete#close_popup() . "<Right>" 47 "inoremap <expr><Up> neocomplete#close_popup() . "<Up>" 48 "inoremap <expr><Down> neocomplete#close_popup() . "<Down>" 49 " Or set this. 50 "let g:neocomplete#enable_cursor_hold_i = 1 51 " Or set this. 52 "let g:neocomplete#enable_insert_char_pre = 1 53 54 " AutoComplPop like behavior. 55 "let g:neocomplete#enable_auto_select = 1 56 57 " Shell like behavior(not recommended). 58 "set completeopt+=longest 59 "let g:neocomplete#enable_auto_select = 1 60 "let g:neocomplete#disable_auto_complete = 1 61 "inoremap <expr><TAB> pumvisible() ? "<Down>" : "<C-x><C-u>" 62 63 " Enable omni completion. 64 autocmd FileType css setlocal omnifunc=csscomplete#CompleteCSS 65 autocmd FileType html,markdown setlocal omnifunc=htmlcomplete#CompleteTags 66 autocmd FileType javascript setlocal omnifunc=javascriptcomplete#CompleteJS 67 autocmd FileType python setlocal omnifunc=pythoncomplete#Complete 68 autocmd FileType xml setlocal omnifunc=xmlcomplete#CompleteTags 69 70 " Enable heavy omni completion. 71 if !exists('g:neocomplete#sources#omni#input_patterns') 72 let g:neocomplete#sources#omni#input_patterns = {} 73 endif 74 "let g:neocomplete#sources#omni#input_patterns.php = '[^. ]->hw*|hw*::' 75 "let g:neocomplete#sources#omni#input_patterns.c = '[^.[:digit:] * ]\%(.|->)' 76 "let g:neocomplete#sources#omni#input_patterns.cpp = '[^.[:digit:] * ]\%(.|->)|hw*::' 77 78 " For perlomni.vim setting. 79 " https://github.com/c9s/perlomni.vim 80 let g:neocomplete#sources#omni#input_patterns.perl = 'hw*->hw*|hw*::'