Posted on 04-11-2007
Filed Under (Computers) by Garoth

Recently more so than ever, I’ve become addicted to using Vim for everything that I do on a regular basis, just about. I would like to tell you about the wonders I’ve discovered. First and foremost, however, is the answer to the question: “What Is Vim?”

Vim is a very old text editor. Very old. It has it’s roots in Vi, which is even older than Vim. In fact, Vim stands for “Vi IMproved.” Now, the question is, why would I want to use such an old text editor? Heck, for the longest time, Vim was only available through command line. Imaging doing word processing with DOS! (Now, though, there is a graphical Vim. To be honest, though, it’s not much different from the command line version.) So what makes Vim worthwhile? Believe it or not, it’s speed makes it worthwhile. I don’t just mean startup speed or file parsing speed. I mean how fast I can can write text files and code in Vim compared to anything else. The way that Vim manages to be faster than just about anything else has entirely to do with what my friend refers to as “forcing the user to get a pHd in keyboard bindings.” Here are some examples of the workflow of Vim:

I have a file open. The file is a grocery list. To move down a line in the list, I can press down arrow or j. To move forward a character, I can press right arrow or l. If I don’t want to wait for the cursor to get where I want it to by pressing j or l all the time, I can very simply press 5j and it will move down 5 lines. Ok, so now imagine I have on my list “Milk, Regular” and I decide I would really rather have Chocolate Milk. In regular word usage, one would move his hand over to the mouse, select the word “Regular” (carefully) and then type in Chocolate… In Vim, however, this is what I would do (assume my cursor is on the correct line, at the start of the line, so hovering over the letter “M”): 2wdwiChocolate. “2w” moves forward 2 words. “dw” deletes a word. “iChocolate” puts me into insert mode and I type Chocolate. Now, this kind of thing may seem very confusing at first, but after considerable “getting used to it,” it comes a bit like breathing. You can do these operations very quickly once you know what you want and have your hands trained to act without thinking. Really, the key to Vim‘s speed is training people to use muscle memory.

Note: there are far too many bindings such as these to mention in this introduction. The more you know, the faster you go Anyway, the point is that I became very used to using Vim. After that, the addiction spread. I am here to tell you about my Vim exploits:

Vimperator Vimperator is a Firefox extension that transforms Firefox into a browser with virtually no user interface and Vim-like keyboard bindings. With Vimperator, I can do everything I used to do with regular Firefox. However, the speed at which I do it is improved. For example, I can go up and down a page using j and k. I can open a new page by pressing “o “. I can bookmark a page using “:bmark -t “. I can set up quick bindings to go to common pages using :qmarks. This allows me to press “gog” and it will take me to garoth.com. Another example would be pressing “gh” — that takes me to my homepage (not a qmark). In short, Vimperator is a bit faster to use than regular Firefox, and it gives me a lot more viewing space. (None of those standard Firefox toolbars eating up space.)

ViewSourceWith ViewSourceWith is another Firefox extension that allows me to actually use Vim to edit text fields in web pages. It does this by opening Vim (or any other text editor) outside of Firefox, letting you edit the text, and pasting it in once you save and exit. It’s not as nice as having Vim embedded into Firefox, but it’s only a couple alt-tab’s worse. The benefit, of course, is being able to use the faster Vim keyboard shortcuts to write things quick. ViewSourceWith with Vimperator really makes Firefox into a Vim based browser

Calendar I am trying to phase out my Gnome toolbars. As such, I no longer have time in my toolbar. I don’t really care about the clock (because I have one on my desk), but it would be very nice to have a calendar when I want one. A solution to this is using the Vim calendar extension. It allows you to type :Calendar in any Vim and have it open a neat multi-month, multi-year calendar. A very nice little tool.

Vim LaTeX Suite Vim LaTeX Suite is another plugin for Vim that allows much easier creation of richly formatted documents. This, to me, is a day-to-day replacement for MS Office and even OpenOffice. Being a university student, I often take notes. Using something like MS Office is possible for this task, but no where near optimal. MS Office can’t do math very easily (not built in, but can be bought from a third party, I hear), and it doesn’t have the speed of Vim. Vim LaTeX Suite (with latex installed) allows Vim users who will spend the time to learn LaTeX to generate all kinds of documents very quickly. LaTeX‘s built in math markup allows you to embed any formula into any document. The output of compiled LaTeX code can be HTML, PDF, DVI, and many more formats. Here is a simple example of LaTeX code that was written by my friend:

\documentclass{article}
\title{Congruences}
\date{\today}
\begin{document}
\maketitle
What time comes 8 hours after 6:00? $14:00 \equiv 2:00$ (mod 12).
\section{Definition}
Let $m$ be fixed positive integer. If $a,b \in Z$ say
that $a$ is congruent to $b$ modulo m'' if $m|a-b$.
...
\end{document}

You can see how it can be used to make rather good things. Again, the power comes from learning a lot of markup syntax. Once you do, though, it’s very handy to use LaTeX. It does a lot of formatting automatically and the result tends to be a very attractive document. Here is a pdf I made once: Solving Inverses

Getting Set Up With Vim and LaTeX on Ubuntu I have noticed that it takes some effort to get set up in Ubuntu these technologies, however. The following is a quick guide to getting it all working smoothly with Vim and Vim LaTeX Suite.

1. Install vim-full (Ubuntu comes with only vim-tiny): “sudo apt-get install vim-full”
2. Install the proper latex package: “sudo apt-get install tetex-base tetex-bin tetex-extras” (or at least just texlive-latex-base if the download is too big for your tastes).
3. Add the following to your .vimrc to make latex-suite work properly:
" VIM-LATEX STUFF
" ---------------
" REQUIRED: This makes vim invoke Latex-Suite when you open a tex file.
filetype plugin on
" IMPORTANT: grep will sometimes skip displaying the file name if you
" " search in a singe file. This will confuse Latex-Suite. Set your grep
" " program to alway generate a file-name.
set grepprg=grep\ -nH\ \$*
" TIP: if you write your \label's as \label{fig:something}, then if you
" " type in \ref{fig: and press  you will automatically cycle through
" " all the figure labels. Very useful!
set iskeyword+=:
let g:tex_flavor="latex"


Anyway, happy vimming

Garoth on 10 June, 2008 at 5:07 pm #

Crud, I need to fix this up. Latest revision doesn’t mention how to actually get latex-suite…

Greg on 7 July, 2008 at 12:21 am #

Holy crap – the Vimperator plugin is amazing! I feel like I’ve found the Long Lost Plugin. Incredible work. I found this page by accident, I was Googling something else, but I’m completely glad I found this. Thank you, thank you, thank you …

Mikey on 15 January, 2010 at 3:17 am #

Hey sweet.. though I’d suggest a couple emendations to your example keystroke to further showcase the power of Vim. Use ‘W’ to skip a WORD (as defined by space delimiters) and use ‘C’ to ‘change’ to the end of the line instead of ‘dwi’. So, ‘WCChocolate’.

On that note, a nifty little trick I’ve picked up recently is using ‘diw’ (delete ‘in’ word), ‘ca{‘ and their siblings. Check them out…