花了好幾天廢了九牛二虎之力終於在win下把ycm插件裝上了
然而在配置插件的時候發現snipmate插件與youcompleteme插件會發生tab鍵沖突
而ycm比較調,直接使snipmate插件完全失效了
在vim中執行以下代碼
:scriptnames
發現snipmate插件是正常加載的
那就可能是發生了鍵沖突
先在vimrc中修改ycm的觸發鍵試試
let g:ycm_key_list_select_completion = ['<c-n>', '<Down>'] let g:ycm_key_list_previous_completion = ['<c-p>', '<Up>']
然而並不行,應該還是是ycm干的。ycm你真流氓,自己都不用tab鍵了,還不讓釋放出來讓別人用。。。
那么試試修改snipmate
按照snipmate的文檔,修改trigger key要改動snipmate.vim/after/plugin/snipMate.vim文件
例如將<tab>改為<C-\>可以將下面兩行
" You can safely adjust these mappings to your preferences (as explained in
" :help snipMate-remap). ino <silent> <tab> <c-r>=TriggerSnippet()<cr> snor <silent> <tab> <esc>i<right><c-r>=TriggerSnippet()<cr>
改為
ino <silent> <C-\> <c-r>=TriggerSnippet()<cr> snor <silent> <C-\> <esc>i<right><c-r>=TriggerSnippet()<cr>
同樣不行。。。。
怒了。。。。不行老子不用ycm了,就當自己這幾天白折騰了!
百度出還有一款類似的插件,嗯。。試試看
https://github.com/SirVer/ultisnips
用vundle將snipmate刪掉
然后在vimrc中增加以下代碼
" Track the engine. Plugin 'SirVer/ultisnips' " Snippets are separated from the engine. Add this if you want them: Plugin 'honza/vim-snippets' " Trigger configuration. Do not use <tab> if you use https://github.com/Valloric/YouCompleteMe. let g:UltiSnipsExpandTrigger="<tab>" let g:UltiSnipsJumpForwardTrigger="<c-b>" let g:UltiSnipsJumpBackwardTrigger="<c-z>" " If you want :UltiSnipsEdit to split your window. let g:UltiSnipsEditSplit="vertical"
保存后重新打開vim
執行
:PluginInstall
會安裝兩個插件。安裝完后新建.cpp文件,測試main<tab>,it works!(若不起作用,請修改ycm的觸發鍵)
還是ultisnips厲害啊。。
后來了解到snipmates在09年已經停止維護了,其小組后來加入了ultisnips中,既然有ultisnips,為什么還存在snipmates呢,因為ultisnips需要python支持
領完,作者是這樣回答的
Q: Should “snipMate be deprecated in favour of UltiSnips”?
A: No, because snipMate is VimL, and UltiSnips requires Python. Some people want to use snippets without having to install Vim with Python support. Yes – this sucks.
One solution would be: Use snippets if they are good enough, but allow overriding them in UltiSnips. This would avoid most duplication while still serving most users. AFAIK there is a nested-placeholder branch for snipMate too. snipMate is still improved by Adnan Zafar. So maybe time is not ready to make a final decision yet.