LogoPhly, boy, phly
the weblog and site of Matthew Weier O'Phinney

Tuesday, September 19. 2006

Vim 7 code completion

I may work at Zend, but I've never been a fan of IDEs. They simply don't suit my programming style. I can usually keep track of file locations in my head pretty easily, and what I really need is a blank slate on which I can write, and one that doesn't consume resource that can better be used running web servers and other programs. Syntax highlighting, good indentation -- these are important, but you can get these from good, minimal text editors very easily. Vim is my editor of choice.

I will admit, though, that one area where I have had IDE-envy is the area of code completion. I often find myself doing quick lookups to php.net or perldoc to determine the order of arguments to a function or method call, or checking for the expected return value. Most of the time, this doesn't take much time, however, so I just live with it.

Today, however, cruising through the blogosphere, I came across an article showcasing some new features of Vim 7.0, and discovered Vim 7's code completion.

Basically, while in insert mode, you can type <C-x> <C-o> to have vim attempt to autocomplete the current keyword. If more than one possibility exists, it shows a dropdown, and you can use your arrow keys to highlight the keyword that you wish to use.

But it gets better! Not only does it do this kind of autocompletion, but it also opens a small 'scratch preview' pane showing the function/method signature -- i.e., the expected arguments and return value!

I thought I had little need for IDEs before... now I have even less! Bram and the rest of the Vim team, my hat's off to you for more fine work!

Posted by Matthew Weier O'Phinney in Programming, Perl, PHP at 17:45 | Comments (6) | Trackbacks (0)

Trackbacks
Trackback specific URI for this entry

No Trackbacks

Comments
Display comments as (Linear | Threaded)

How do you open the preview window? Is it supposed to open automatically when 'ing?
#1 Anonymous on 2006-09-22 05:16 (Reply)
I did some experimentation, and the preview pane opens when there are mulitple matches for a string, and you are then scrolling through them to select the one you want.

So, for instance, if you type 'array_' and then [C-x][C-o] to do completion, it will provide a dropdown of matches; as you scroll through them using the arrow keys, the preview pane will open and show the method signatures.
#1.1 Matthew Weier O'Phinney (Link) on 2006-09-22 09:06 (Reply)
There's got to be another way for this... I hope I'll find it one day :-) I'm usually using autocompletion to avoid typos, I'm trying to avoid using the dropdown as much as possible (I usually work through SSH and it takes some time until it gets to me).

Maybe you (or others may find this usefull): I've see that the omnisearch is rather slow (from the name I think it searches through alot of words). Instead you can use the [C-n] (or [C-p]) directly. It searches through the files listed in the cpt var (`:set cpt` to see its contents).

I have cpt set to `.,tags_file,path_to_php_syntax_file` - it searches through the current buffer, tags file and php keywords.

A great tip on this issue is http://www.vim.org/tips/tip.php?tip_id=102 - maps TAB to . Specially usefull if you're used to *nix shell "completion".
#1.1.1 Anonymous on 2006-09-22 09:21 (Reply)
how do you choose between the omnisense choices without arrowing through them all? also how do you delete what it autocompletes in the case where it got it wrong?
#2 jona on 2007-03-14 23:50 (Reply)
Thanks for the short introduction! I'm referring to it on my blog.

Do you know if there is a way to add my own functions to the code completion feature? That would be immensly helpful.
#3 Eike (Link) on 2009-04-07 16:00 (Reply)
great thing ;-)

I'm also interessted to get this work with my own stuff.
#3.1 hoschi on 2009-05-19 13:18 (Reply)
yeah, and you can map the heavy autopletion with a key like Tab :-)
in your .vimrc

function! SuperTab()
if (strpart(getline('.'),col('.')-2,1)=~'^\W\?$')
return "\"
else
return "\"
endif
endfunction
imap =SuperTab()
#4 dude (Link) on 2009-07-27 11:04 (Reply)

Add Comment

Standard emoticons like :-) and ;-) are converted to images.
E-Mail addresses will not be displayed and will only be used for E-Mail notifications

To prevent automated Bots from commentspamming, please enter the string you see in the image below in the appropriate input box. Your comment will only be submitted if the strings match. Please ensure that your browser supports and accepts cookies, or your comment cannot be verified correctly.
CAPTCHA

 
 
  • Home
  • Resume
  • Blog
  • Phly PEAR Channel
  • Contact Me
  • About this site

ZCE

Zend Education Advisory Board Member

Add to Technorati Favorites

Calendar

Back March '10 Forward
Mon Tue Wed Thu Fri Sat Sun
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31        

Quicksearch

Links

  • PHLY - PHp LibrarY
  • Paul M. Jones
  • Mike Naberezny
  • Shahar Evron
  • Planet PHP
  • Zend Where I now work
  • Garden.org Where I once worked

Archives

March 2010
February 2010
January 2010
Recent...
Older...

Categories

XML Linux
XML Personal
XML Aikido
XML Family
XML Programming
XML Dojo
XML Perl
XML PHP

All categories

Syndicate This Blog

XML RSS 0.91 feed
XML RSS 1.0 feed
XML RSS 2.0 feed
ATOM/XML ATOM 0.3 feed
ATOM/XML ATOM 1.0 feed
XML RSS 2.0 Comments

Show tagged entries

xml best practices
xml books
xml conferences
xml cw09
xml decorators
xml dojo
xml dpc08
xml file_fortune
xml git
xml linux
xml mvc
xml oop
xml pear
xml perl
xml personal
xml php
xml phpworks08
xml programming
xml rest
xml ubuntu
xml vim
xml webinar
xml zendcon
xml zendcon08
xml zendcon09
xml zend framework
© 2004 - present, Matthew Weier O'Phinney
matthew-web <at> weierophinney.net