Vim Recipes

June 4th, 2009

A coworker sent out the following link to the Spacewalk mailing list.

Vim Recipes

Don’t know what Vim is? Google it, I haven’t gotten around to blogging about it and Emacs yet. After you’ve googled it, install it. Yes, they have a Windows version.

Rather than being a straight user guide, it’s more of a guide on how to do useful shit in Vim. I took to Emacs keys much more easily (to the point that I remapped IntelliJ to use the common ones), but I’m really trying to force myself to get better with Vim. The recipes guide reads much better than any of the other tutorials I’ve looked into for Vim and has already shown me a number of useful tips.

For instance, the one thing that has always bothered me about Vim was how many steps it takes to save a file. I’m the kind of person who instinctively saves whatever I’m working on every time I stop to think. I’ve lost too much time by fat fingering something and closing the window without saving. In Emacs, that’s a very quick sequence:

Ctrl-x, Ctrl-s

It may look a little weird, but after using Emacs for 10 minutes, an easy key stroke to mindlessly use. In Vim, it takes a few more steps:

Esc  (to exit insert mode)
:w
i  (or a, to enter insert mode again so I can, ya know, actually type something)

That’s a lot of movement around the keyboard for something I do several times a minute (I stop to think a lot). Page one of that recipes guide already showed a useful way around that:

Use [Ctrl]+o in Insert mode to switch to Normal mode for one command, then return to Insert mode. For example, [Ctrl]+o gqas enters Normal mode, reformats the current sentence, then returns you to Insert mode.

In other words, it eliminates both the need to press escape as well as having to explicitly enter back into insert mode. So my mindless save now looks like:

Ctrl+o
:w

Much nicer. Even if that was all I picked up from the guide, it’d have been well worth it.

I won’t go into more specifics, but I was able to easily find information on repeating commands. I tend to use a lot of dividers in my text files, so being able to quickly generate 60 hyphens as a section header was a sore spot when learning Vim after Emacs. I’m also a big fan of temporary macros to repeat a sequence of changes, which I’m still figuring out how to do in Vim.

Eventually I want to write a bit more of a general introduction blog on Vim and Emacs (where I may explain the religious war between the two) in hopes I can convince my students to learn a real text editor (no, Wordpad doesn’t count and you ask for help while using Notepad, I’m docking your grade). I can’t stress enough that at some point in your career you will find yourself on some form of Linux/Unix/Solaris box where at least being able to navigate and edit text in Vi is pretty much required knowledge.

Comments are closed.