Question

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?

Was it helpful?

Solution

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)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top