Enable vim code (Python) auto complete


Beginning version 7 of vim, it has this nice auto completion feature. It is by default however limited to words that has already been in the current workspace. To use it, simply press [ctrl] +n or [ctrl] + p key while in edit mode. For example:

We can however *teach* vim to autocomplete a whole bunch of other stuffs as well, by using something so called Dictionaries. With this idea we can have auto completion for Python, Ruby, PHP, Bash, and any other programming languages code.

For an example, let’s try to install Python dictionary, by downloading it from here:


http://www.vim.org/scripts/script.php?script_id=850

The next thing to do is to extract the downloaded file to the appropriate folder:

shakir@herugrim ~ $ mkdir ~/.vim
shakir@herugrim ~ $ tar xvzf pydiction-0.5.tar.gz -C ~/.vim

and add this lines to your ~/.vimrc (be sure to replace "/home/shakir" to your own home directory)

if has("autocmd")
    autocmd FileType python set complete+=k/home/shakir/.vim/pydiction-0.5/pydiction isk+=.,(
endif " has("autocmd"

and let’s see the result:

Browse around the Vim script page and your customized Vim could be just as good if not better than some IDEs.. :)


Tags: ,

12 Responses to “Enable vim code (Python) auto complete”

I can’t understand why but this doesn’t work for me:

“C:\Program Files\Vim\vim71\dic\python is a place where pydiction resides.
if has(“autocmd”)
autocmd FileType python set complete+=k/$VIMRUNTIME\dic\python\pydiction isk+=.,(
endif ” has(“autocmd”)

have you tried complete+=k/”C:\Program Files\Vim\vim71\dic\python\dic\python\pydiction” …., and surely place pydiction at C:\Program Files\Vim\vim71\dic\python\dic\python\pydiction .
I’m guessing as i’m not using windows myself, but maybe you can try and report how it goes

Yes, Shakir, I tried that as well, but no luck :( .

This python autocompletion feature is only working if I set in _vimrc:
—–
set dictionary=$VIMRUNTIME\dic\python\pydiction
—–
I then can call autocomplete by consecutive pressing Ctrl+x and Ctrl+k. But in this way, as far as I understand, the pydiction is called for any file type, and in anyway it is not working by just pressing Ctrl+n or Ctrl+p.

More ideas?

Ur missing a bracket in your Code:

if has(“autocmd”)
autocmd FileType python set complete+=k/path/to/pydiction isk+=.,(
endif ” has(“autocmd”)

For Windows paths use: complete+=kC:/Vim/pydiction-0.5/pydiction
where C:/Vim/pydiction-0.5/ is the folder containing the pydiction file.

Thanks M:
It’s working.

Nice!

Wow, that’s very nice. Didn’t know this auto complete feature. Thanks a lot. :)

Could you update your post for the pydiction-1.2. I can’t seem to get it work.

If I type :help ftplugin, i get to see the help for the plugin… But it seems to not find the
complete-dict. I am using vim 7.1.138 on ubuntu hardy.

Thanks to your article I could setup pydiction!

Cheers

binom, read the readme file inside the zip


Leave a Reply

Advertisement