使用VIM,如何同时使用snipMate和pydiction(共享<tab>键)?

16

我正在尝试同时在vim中使用snipMatepydiction - 然而,两者都使用<tab>键来执行他们的智能自动完成代码片段渲染功能。

当安装了pydiction时,snipMate停止工作。我认为这是因为它们不能同时拥有<tab>键。如何让它们一起工作呢?

我不介意将其中一个映射到另一个键,但我不太确定如何做到这一点...(也许将pydiction映射到<ctrl-n>键,以模仿vim的自动完成?)。

以下是相关的.vimrc:

filetype indent plugin on 

autocmd FileType python set ft=python.django 
autocmd FileType html set ft=html.django_template 

let g:pydiction_location = '~/.vim/ftplugin/pydiction-1.2/complete-dict'
3个回答

15

这是来自Snipmate帮助文件的内容 :)

                                                              *snipMate-remap*
snipMate does not come with a setting to customize the trigger key, but you
can remap it easily in the two lines it's defined in the 'after' directory
under 'plugin/snipMate.vim'. For instance, to change the trigger key
to CTRL-J, just change this: >

 ino <tab> <c-r>=TriggerSnippet()<cr>
 snor <tab> <esc>i<right><c-r>=TriggerSnippet()<cr>

to this: >
 ino <c-j> <c-r>=TriggerSnippet()<cr>
 snor <c-j> <esc>i<right><c-r>=TriggerSnippet()<cr>

太好了 - 谢谢!也许在我的所有搜索中,我应该更仔细地查看帮助文档。哈哈。 - thornomad
3
现在不再是这样,文档指定可以使用“imap <C-J> <Plug>snipMateNextOrTrigger”和“smap <C-J> <Plug>snipMateNextOrTrigger”来重新映射。 - TKrugg
1
+1 @TKrugg,请查看我的点文件提交,其中包含重新映射。https://github.com/simeonwillbanks/dotfiles/commit/660b0505c82157656e15d47cd43108d2d39409db - simeonwillbanks

7

或者,您可以编辑~/.vim/after/ftplugin/python_pydiction.vim并将Tab更改为其他内容:

" Make the Tab key do python code completion:
inoremap <silent> <buffer> <Tab> 
         \<C-R>=<SID>SetVals()<CR>
         \<C-R>=<SID>TabComplete('down')<CR>
         \<C-R>=<SID>RestoreVals()<CR>

" Make Shift+Tab do python code completion in the reverse direction:
inoremap <silent> <buffer> <S-Tab> 
         \<C-R>=<SID>SetVals()<CR>
         \<C-R>=<SID>TabComplete('up')<CR>
         \<C-R>=<SID>RestoreVals()<CR>

4

我相信自2009年karel提供答案以来,更改触发键的方式可能已经发生了变化,但它仍然在同一目录中,即“after/plugin/snipMate.vim”中。我也在帮助文件中找到了它:

 *snipMate-trigger*
snipMate comes with a setting to configure the key that is used to trigger
snipMate. To configure the key set g:snips_trigger_key to something other than
<tab>,e.g. <c-space> use:

 let g:snips_trigger_key='<c-space>'

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接