Hacking a Perl Hack for Python: Autocomplete in vim

by Jeremy Jones

I've been thumbing through the Perl Hacks book lately. Some of the "Productivity Hacks" are (nearly) applicable to Python as well as Perl hackers. For example, most of "Hack #5: Autocomplet Perl Identifiers in Vim" applies directly to Python vim users. I've been using the CONTROL-N thing for years now. Basically, if you have a "word" in a file that you are vimming, you type the first couple of letters of it, hit CONTROL-N, vim will match and complete that already-entered word. But, as chromatic pointed out, it won't match (in Perl) "words" that look like "Foo::Bar". Nor will it match (in Python) "words" that look like "foo.bar". The solution to this for Perl is to add "set iskeyword+=:" to your .vimrc. The solution in Python is to add "set iskeyword+=." to your .vimrc. Actually, I added this to my ".vim/ftplugin/python.vim" so that this would only get loaded when I'm editing a Python file. Now, I have greater joy in my vimming experience.

Anyway, this was a great hack that was easily modified to work for Python. There are other useful hacks that are very applicable to Python folk. I don't know how many of these I want to give away for free, though. I might make you go buy the book :-)


2007-10-29 08:36:29
Here is how to do an autocomplete for python in vim
Autocomplete vim python
2008-06-29 23:07:36

i am studying perl script for windows system administration. so please kindly help to me for am i acheiveing my goal.