efficient editing with VIM

I’ve used VIM as my editor for several years, and I consider myself to be a competent user, but I learned several new features from Jonathan McPherson’s page about efficient editing with VIM.

Here are the highlights. I will be using the first two from now on and will probably wonder how I managed without them. The second two will still be useful, but I probably won’t use them all the time.

Control-N: Keyword completion. Just type the first few letters of the word (a long variable name that is already in the code) and then hit Control-N. If the first match isn’t right, just keep hitting it and it will cycle through all the possibilities. Using this feature alone will save me oodles of time.

]p: Just like p for pasting, but it automatically adjusts the indent level of the pasted code to match the indentation of the cursor location. This will save me from having to spend time reindenting code.

gd: Put the cursor over a variable, and it will go to the definition or declaration of that variable. It gets confused in Perl code, but seems to do alright in C and Java.

K: Go to the man page of the word you’re on. For instance, if the cursor is over strncpy, it will display the strncpy man page. It’s very useful in C, but probably not much use in other languages.

One feature that wasn’t listed but has been useful to me is the command history.

q: It’s been especially useful when I’ve been doing fairly complex search and replaces and I need to do several variations. Instead of having to type the whole thing in again, just hit q: (you’ve probably seen this when you were trying to exit and accidentally hit the q before the colon) and you can go back and edit previous commands, then hit enter to execute the command.

Comments

 (Post a comment) | Comments RSS feed
  1. Does q: do something different than : followed by the up arrow? I guess it’s nice to have a version of it that doesn’t require leaving the home row, even if they do the same thing.

    I’m not surprised it gets confused on perl code. I hate how heavy and complicated perl syntax is.

    Thanks for pointing these out, they look very useful.

    Comment by Levi on November 23, 2004 @ 10:03 am
  2. I wasn’t aware of : followed by the up arrow, but I tried it out and it is slightly different. q: shows several at a time, splitting the window, and as you know, : up arrow just goes through one at a time.

    Comment by dan on November 23, 2004 @ 10:53 am

Comments are closed