vim tricks

In: Computers|Linux Tips|Lists|Programming

8 Nov 2007

If you’re cool like me, you spend a decent amount of time in vi editing files. Despite all the fancy IDEs and the like, nothing beats uploading your PHP script to the webserver and editing in place. I don’t profess to be a vi expert. I’m far from it, in fact. But for those that are like me–comfortable working in it but far from being a master–here are a few tips:

  • Typing “G” (in command mode, but not as a : command!) takes you to the last line of the file.
  • ma, where a is a letter a-z, sets a as a ‘mark’. You can then issue commands reflecting that mark. For example, I wanted to delete about 500 lines from a file. But I didn’t know how many lines there were, so “500dd” wasn’t a viable option. In my case, I marked the last line I wanted to delete with a, went up to the first line I wanted to delete, and then typed d’a to delete from the current line to mark a. Note that, as you’re doing this, there’s no indication of it.
  • . (a single period) runs the last command again. Handy way more often than I’d expect!
  • :wq is probably the most well-known command. But ZZ (not :ZZ) is easier and does the same thing!

This is a handy reference, by the way. So isn’t the O’Reilly book, but you can’t Google your way through that.

Related posts:

  1. vim Trick of the Day
  2. Getting Familiar with the CLI
  3. Tech Tricks
  4. Custom LogFormat with Apache
  5. vim Tip: Delete all lines which….

2 Responses to vim tricks

Avatar

Mr. T

November 8th, 2007 at 11:41 pm

So isn’t the O’Reilly book

“So isn’t?” Do you mean “so is?” No matter how often I hear that I will never get used to it.

Avatar

Matt

November 8th, 2007 at 11:51 pm

Ack, it’s contagious.

I never got that phrase either. Kind of like, “I could care less.” It’s backwards.

Comment Form

On Other Sites

  • Matt: Hey Victor, A couple good resources for you... http://www.scanboston.com/boston.htm is really det [...]
  • victor: Hi i just got a uniden bearcay scanner and have no local or regional frequency directory.just 1 460 [...]
  • Matt: I do use them periodically. I bought a few i760's, for perhaps $10 apiece in a lot, on eBay a while [...]
  • Marin: Did you eventually end up going with an iDEN phones using Direct Talk? I had some i560's a few year [...]
  • Dan: fyi, EOD = explosive ordnance disposal [...]