Feb 17, 2010

Hacking SuperTab.vim

I have been unhappy about the longest common text of auto-complete provided by VIM for a long long time.
I try to find a good solution on the Internet, but all I got is
Put
completeopt += menuone,longest
in your .vimrc
It does provide a longest common text of auto-complete FOR THE FIRST TIME. After I type one more character and press <tab>, it just starts to move on the popup menu. No more longest common text of all matches anymore.
To work around this, I hacked the SuperTab to provide longest common text.
Here is how:

  1. open supertab.vim in your /plugin directory
  2. find function! s:SuperTab(command)
  3. change the code
    " handle 'context' completion.
    if b:complType == 'context'
      let complType = s:ContextCompletion()
      if complType == ''
        exec "let complType = \"" .
          \ escape(g:SuperTabContextDefaultCompletionType, '<') . "\""
      endif
        return complType . key
    endif

to
    " handle 'context' completion.
    if b:complType == 'context'
      let complType = s:ContextCompletion()
      if complType == ''
        exec "let complType = \"" .
          \ escape(g:SuperTabContextDefaultCompletionType, '<') . "\""
      endif
         if pumvisible()
             return "\<ESC>a" . complType . key
         else
            return complType . key
        endif

    endif

The idea is simple. Just close the popup menu each time users press <tab>, since VIM will do longest common text before the popup menu appears.

0 comments:

 
TEMPLATE HACKS AND TWEAKS BY [ METAMUSE ] BLACKCAT 1.1
/scripts/shBrushJScript.js'/>