1

我在 vim 中使用 supertab 插件。
这些是我的默认设置(在 _vimrc 中)

let g:SuperTabDefaultCompletionType = '<c-x><c-k>'  -->(dictionary)  
let g:SuperTabRetainCompletionDuration = "completion"  
let g:SuperTabLongestEnhanced = 1  
let g:SuperTabLongestHighlight = 1  

我创建了这个脚本来动态选择带有supertab的omnicomplete:

function! SuperTabFunction()
  if !exists("WhatSuperTab")
    let WhatSuperTab = "SuperTab function?"
  endif
  if !exists("MenuSuperTab_choices")
    let MenuSuperTab_choices = "&Current page\n&Spellchecker\nSentence\nCode"
  endif
  let n = confirm(WhatSuperTab, MenuSuperTab_choices, "Question")
  if n == 1
    let g:SuperTabDefaultCompletionType = '<c-x><c-m>'
    so $VIM/vimfiles/plugin/supertab.vim
  elseif n == 2
    let g:SuperTabDefaultCompletionType = '<c-x><c-k>'
    so $VIM/vimfiles/plugin/supertab.vim
  elseif n == 3
    let g:SuperTabDefaultCompletionType = '<c-x><c-l>'
    so $VIM/vimfiles/plugin/supertab.vim
  elseif n == 4
    let g:SuperTabDefaultCompletionType = '<c-x><c-o>'
    so $VIM/vimfiles/plugin/supertab.vim
  else
    return ''
  endif
endfun 

  nmap <silent> <C-S-tab> :call SuperTabFunction()<CR>
  imap <silent> <C-S-tab>  <esc>:call SuperTabFunction()<CR>a

当我调用上述函数并选择 pe "Sentence" 时,我可以使用超级制表符来完成句子当我再次调用上述函数并选择 pe "Spellchecker" 时,将正确的值分配给 g:SuperTabDefaultCompletionType 但它仍然会替换句子。

我在这个功能中做错了什么?

4

1 回答 1

1

您是否尝试过调用提供的函数而不是直接更改全局变量?

" SuperTabSetDefaultCompletionType(type) {{{
" 全局可用的功能,用户可以使用它来设置默认值
" 当前缓冲区的完成类型,就像在 ftplugin 中一样。
功能!SuperTabSetDefaultCompletionType(type)
于 2012-03-15T07:45:30.343 回答