Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does SuperTab output self when I press <tab>?

The Setup

In my .vimrc I have the following lines:

" .vimrc
let g:virtualenv_directory="/Users/Kit/Development/virtualenv"

Then in ~/.vim/ftplugin/python/virtualenv.vim I have these:

py << EOF
import os.path
import sys
import vim
if 'VIRTUAL_ENV' in os.environ:
    project_base_dir = os.environ['VIRTUAL_ENV']
    sys.path.insert(0, project_base_dir)
    activate_this = os.path.join(project_base_dir, 'bin/activate_this.py')
    execfile(activate_this, dict(__file__=activate_this))
    print "virtualenv in os.environ!"
EOF
VirtualEnvActivate my-virtualenv-python-2.7

In ~/.vim/ftplugin/python/virtualenv.vim I have these SuperTab settings:

setlocal omnifunc=pythoncomplete#Complete
setlocal completeopt=menuone,longest,preview
let g:SuperTabDefaultCompletionType="<c-x><c-]>"

In my working directory, where I always work from, I executed the following bash command to generate a TAGS file for all my .py files

find . -name '*.py' -type f -print0 | xargs -0 etags -l python

The problem

For example, I have a main.py which has an object app inside it, such that the following script works fine:

import main
new_app = main.app() # works totally fine Python-wise

If, for example, I write some new code and try to use SuperTab omnicompletion:

import main
new_new_app = main.<Tab>

This is what I get:

new_new_app = mainself.

And if I press Tab several times:

new_new_app = mainselfselfselfself.

What works for me

If, however, I do the following:

new_new_app = main.a<Tab>

I get a whole list of a.. objects that include those that don't belong to module main.

What I want

If I set the following in .vimrc:

let g:SuperTabDefaultCompletionType="context"

Then, I use a module from the standard Python library:

import sys
sys.<Tab> # This will still result in sysselfselfself.
sys.p<Tab> # This will result in the correct list of `sys` members beginning with `p`

But the "context" setting won't work on my own modules:

new_new_app = main.a<Tab>
# Will say at the bottom: Omni completion (^O^N^P) Pattern not found

The Question

How should I set up omnicompletion and SuperTab so that it behaves for my own modules as for the standard library modules? As well as eliminate the selfselfself. annoyance?

like image 645
Kit Avatar asked Feb 08 '12 12:02

Kit


1 Answers

As you point out, this is caused by snipmate: https://github.com/garbas/vim-snipmate/issues/65

I also proposed a solution: https://github.com/garbas/vim-snipmate/pull/84

It did not get accepted, because snipmate should not be context sensitive.

There are two solutions for this:

  1. Take my snipmate fork:

    https://github.com/davidhalter/vim-snipmate

    Which is probably not the best idea, since it's just my fork and I don't actively maintain it.

  2. Fork https://github.com/honza/snipmate-snippets and remove the mapping for the dot (Using the dot will not be possible anymore, to complete self).

like image 189
Dave Halter Avatar answered Oct 04 '22 21:10

Dave Halter