Thursday December 27, 2007 08:41

Enable vim code (Python) auto complete

Posted by shakir as Information Insemination





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.. :)

I have imported this post to my other site and maintain it there.





Tags: ,



12 Responses to Enable vim code (Python) auto complete

Arthur Khakimov

February 6th, 2008 at 2:25 pm

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”)

shakir

February 6th, 2008 at 11:33 pm

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

Arthur Khakimov

February 7th, 2008 at 1:25 am

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?

What a beard » Blog Archive » links for 2008-02-11

February 12th, 2008 at 9:13 am

[...] Enable vim code (Python) auto complete | /home/shakir (tags: vim python) [...]

Xray99

May 22nd, 2008 at 9:03 pm

Ur missing a bracket in your Code:

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

M

January 23rd, 2009 at 3:01 pm

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

Vincent Lin

March 24th, 2009 at 11:47 pm

Thanks M:
It’s working.

Qnix

March 29th, 2009 at 12:29 am

Nice!

CTS GmbH

June 27th, 2009 at 12:29 am

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

binom

September 7th, 2009 at 10:14 am

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.

Kenny Meyer

October 7th, 2009 at 9:44 am

Thanks to your article I could setup pydiction!

Cheers

bahodir

October 14th, 2009 at 9:15 am

binom, read the readme file inside the zip

Comment Form