使用 supertab 动态更改omnicomplete

发布于 2024-12-18 18:43:48 字数 1504 浏览 1 评论 0原文

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

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

我创建了这个脚本来动态选择带有超级选项卡的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“拼写检查器”时 正确的值被分配给 g:SuperTabDefaultCompletionType 但它仍然取代了句子。

我在这个函数中做错了什么?

I use the supertab plugin in vim.
These are my default settings (in _vimrc)

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

I created this script to select omnicomplete with supertab on the fly:

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

When I invoke above function and choose p.e. "Sentence"
I can use super tab to complete sentences
When I invoke above function again and choose p.e. "Spellchecker"
The correct value is assigned to g:SuperTabDefaultCompletionType
but it still replaces sentences.

What did I wrong in this function?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

祁梦 2024-12-25 18:43:48

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

" SuperTabSetDefaultCompletionType(type) {{{
" Globally available function that users can use to set the default
" completion type for the current buffer, like in an ftplugin.
function! SuperTabSetDefaultCompletionType(type)

Have you tried calling the provided function instead of altering the global variable directly?

" SuperTabSetDefaultCompletionType(type) {{{
" Globally available function that users can use to set the default
" completion type for the current buffer, like in an ftplugin.
function! SuperTabSetDefaultCompletionType(type)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文