Kevin wrote an execelent post on text editors for LaTeX recently. He did a nice job covering a host of editors there. As I’ve said before, I’m a big fan of Vim. I don’t have anything against other text editors, but I think Vim has a lot of advantages and is really good for writing LaTeX and other plain text documents. But Vim isn’t exactly easy to learn. (As Kevin notes, LaTeX isn’t easy to learn either, so don’t let the learning curve dissuade you from trying Vim out.) Though I can’t make Vim easy to learn, I think I can serve as a bit of a guide, and I can hopefully offer some advice and suggestions to make getting started with Vim and LaTeX easier. So this will be the first in a series of posts that explains how I use Vim for philosophy papers.
Vim is odd
The first thing you need to know about Vim, as Kevin and I have both mentioned in the past, is that Vim is odd. It is ‘modal’. That is, there are multiple modes in which you operate. When you open up Vim, you are in NORMAL mode. In normal mode, no key means what you thought it would! Type a ‘D’ in normal mode and you will not get a ‘D’ under the cursor—you will have deleted the rest of the line from the cursor onward. Whoops.
If you want to write anything in Vim, you need to hit ‘i’. That puts you in INSERT mode. In insert mode you can insert text. When you are writing—putting words on the page—you are in insert mode. In insert mode, Vim is no different than any other text editor. To get back into normal mode, you hit the escape (or Esc) key.
As Kevin mentioned, Vim is an extension of the old vi text editor. The only modal editors that I know of are the descendants of vi. Using Vim is unlike writing with any text editor you’ve ever used.
Vim’s strength
Why use a modal editor? If you have two modes, then every key can have twice as many meanings. Instead of the ‘i’ key having two meanings (the lowercase and uppercase letter ‘I’), with a modal editor it can have four (the two ’I’s, plus the ‘insert a letter in front of the cursor’ and the ‘insert a letter at the start of the line’ commands). This means that the possible keyboard shortcuts are greatly increased. And most of the shortcuts are really easy to use. Instead of holding Shift and Command (or Control), hitting the arrow until you’ve hit the end of the sentence, and then typing Command+C or Control+C to copy the current sentence (a serious wrist workout), with Vim you only have to hit Escape, then ‘y)’.
Efficiency isn’t everything. And the Escape key can be a long way away (though you can set it up such that a pair of quick semicolons is just like hitting Escape, which makes entering normal mode easy). But I think it is hard to deny that both navigating and editing a paper are more efficient in Vim, once you learn your way around the commands. I think it is more efficient than other text editors after you learn just a few basic commands, but the more you learn, the more efficient it is.
Another advantage of Vim: it is everywhere. There are really two versions of Vim, one graphical and one you use in a terminal emulator. On the systems I’ve used (Mac OS X and Arch, Zenwalk, and Puppy linux), vi or Vim has been the default editor in the terminal. This means you’ll encounter it if you do anything in the terminal (unless you change your preferences.) The first time I used the version control system git on my Mac, I was dumped into an instance of Vim to edit a file and had zero clue what to do. I actually ended up killing the program because I couldn’t figure out how to type anything. Later that day, when I stumbled upon ‘i’ and began typing, I couldn’t figure out how to save and close the file, so I had to abort the mission again! (FYI: you save a file with :w in normal mode, and you close the file with :q. To save and close type :wq.)
And you can install Vim on any system. So if you split your time between a linux and Mac computer, you can have one text editor that you use on both. Kevin discusses some other equally portable text editors. I wonder if Vim isn’t more portable than many editors, even those that have both Mac and Linux versions. This is because all your Vim configurations and preferences are done using plain text files. If you get a new computer, you just transfer your .vimrc file, and your new Vim is just like your old Vim—no messing around with check boxes and other ways to set your preferences. Of course, this ‘advantage’ is only the result of the old-fashioned way Vim sets preferences in a text file, so maybe I’m making a virtue of necessity here!
How to get Vim
Vim is easy to install on most Linux distributions and on a Mac. You can find download details here.
- If you are using Linux, just follow your normal steps for installing packages. If you install Vim, you’ll get the most recent versions of both the terminal and graphical versions of Vim.
- If you are using a Mac, you’ll want to install MacVim. I highly recommend installing the most recent snapshot instead of the stable version, at least until MacVim 7.3 comes out. Snapshot 52 has an update that you’ll need if you want to use all the plugins I recommend later. Download the file, then open the folder you just downloaded. Drag the MacVim file into your applications directory. Then drag the mvim application to somewhere in your PATH (somewhere like
/usr/local/bin). When you install the graphical MacVim, you are also installing the most recent version of the command-line Vim. - [Update:] There is another option for installing MacVim (on a Mac, obviously): the Homebrew package management program. I highly recommend Homebrew. I discuss installing Homebrew and using it to install MacVim in another post.
- I’m going to punt on the Windows installation instructions. If you use a Windows PC, take a look at the download instructions here. Hopefully you’ll be able to tell what you need!
Learning Vim
Now for the hard part: learning Vim.
Your best bet is to start out with the built-in Vim tutor. This is a 30 minute or so hands-on tutorial. Probably the easiest way to do this is the way the MacVim site suggests: open up Vim (you should be able to access the graphical version of Vim in your Applications folder). You’ll be in insert mode. Type :!cp $VIMRUNTIME/tutor/tutor ~/Desktop. The letters you type will appear at the very bottom of your window. Hit Enter and you will have created a file called ‘tutor’ on your desktop (change the directory if you like). Then click File -> Open, navigate to the new ‘tutor’ file, and open it. Then follow the directions.
(If you want, you can just open Vim and type, in normal mode, :vimtutor. That will create a temporary version of the file and open it.)
The only way to learn to use Vim is to use Vim. You might want to start small—only use Vim for taking notes or for editing configuration files. Or you might want to go all in and start using Vim for all your text editing needs. With a graphical version of Vim, you could use Vim just like any other text editor and get by without knowing hardly any commands. All you need to know is that ‘i’ will put you in insert mode (let you type a paper) and the Escape key will put you in normal mode.
Vim can be really overwhelming. I think the best way to learn to really use Vim is to pick a small subset of commands to use, and then keep adding subsets as you learn the one you are on. Start out by committing to save your work by typing :w in normal mode instead of by clicking File -> Save or Command+S (or Control+S). Or start by using the basic Vim navigation: ‘h’ moves left one character, ‘j’ moves down one line, ‘k’ up one line, ‘l’ right one character. And maybe throw in ‘G’ to move to the bottom of the file and ‘gg’ to move to the top. Then, once you are comfortable with those, you can start using ‘(’ to move to the start of the sentence, ‘)’ to move to the end, and ‘{’ and ‘}’ to move to the next empty line. You might even think about making a cheat sheet that lists just a handful of commands you are going to use. In no time you’ll be adding more.
(You can find some nice cheat sheets that will teach you a smallish chunk of Vim at a time. Here is one I like, though the ‘lessons’ might include too many commands for a beginner.)

Among all material avaliable to learn vi/vim, I would like to point out the videos in http://www.derekwyatt.org/vim/vim-tutorial-videos/
Hi Felix, Thanks for that link. I just stumbled upon the first video in that series the other day and found it really enjoyable. But I hadn’t had a chance to look at any others. I’m glad to hear they are good. I’ll look forward to checking them out.
(By the way, for some reason the links on Derek Wyatt’s page don’t go to the right places on Vimeo. So here’s a direct link to the videos Felix is talking about.
I also quite like Vimcasts, which I’ve mentioned here before. There are lots of people out there trying to explain how to use Vim. I’m happy for it, since you can always learn something new about it!
I haven’t been playing with vim very long, but I do have one quick tip to add, which I’ve found handy, which is to remap CapsLock to Escape on your keyboard. I can’t think of any circumstances in which I‘d ever intentionally hit the CapsLock key, nor any circumstances in which I’d want to. On the other hand, I hit it unintentionally all the time, which is annoying. And the one key you need to press all the time when using vim which is far from the home row is Escape. So this kills two birds with one stone.
(On Ubuntu running gnome, you can do this through System > Preferences > Keyboard > Layout > Options > CapsLockKey Behavior. I’m sure there are ways to do it for mac and Windows too. (For Windows you could use AutoHotKey, etc.))
Another good reason to learn vim occurred to me recently (–prompted in part by mention of trying to edit LaTeX using an iPad on Peter Smith’s blog–), which is that it has a text-only mode and so you can use it through SSH. The iPad has an SSH client. (I won’t buy an iPad myself, but I may someday buy a similar linux-based product; and this could be handy in a lot of other situations too.) Using SSH you could connect even to your home computer and use your own LaTeX system remotely. (In case you need custom packages, etc., not provided by the web-based LaTeX systems.)
I just need to figure out how to set up a vim server so you can use the LaTeX box compiler without escaping back to the command line. You know anything about that, Charlie?
Kevin, Remapping Caps Lock is a good idea. I actually favor remapping ‘;;’ to Escape, but the idea is the same (I did the Caps Lock thing one time, and all of a sudden I needed all caps everywhere. It drove me crazy, so I had to switch back. I don’t think I’ve needed Caps Lock again sense, though…)
In an upcoming installment in this series of posts I’ll share some of my favorite key mappings for Vim, and I’ll also share some plugins I like.
Your question about a vim server is way over my head. I think you are the resident server guy, so if you don’t know the answer, I know I won’t!
It has been suggested to me that remapping Caps lock to CTRL is a good idea for emacs, because to make something all caps in emacs is a matter of marking the region you want capped and then doing C-x C-u. I wonder if there’s a similar shortcut in vim that would mean you wouldn’t lose the “functionality” of caps lock…
Also, given what ESC does in vim, it seems like mapping it to a key one regularly hits accidentally seems like a dangerous idea, no?
I don’t know if remapping caps lock to ESC is dangerous in Vim. If anything, caps lock is dangerous. A ‘U’ means something different than a ‘u’, and there have been times when I hit Caps Lock on accident and then got into an odd situation as a result. You can (almost) always undo any changes you make by hitting ‘u’ over and over (I’m sure there is a more efficient way), so if you were to go into normal mode on accident (via ESC), you likely wouldn’t do any lasting damage on accident.
There is a way to make a word, sentence, etc. all caps once it has been typed. You can highlight a region (hit ‘v’ to go into visual mode and highlight regions), then ‘U’ will turn that all into caps. A ‘u’ on a highlighted region will make it lowercase. A faster method is to navigate to the start of the section, then hit ‘gU’ and the key to navigate to the end of the section. So if you are in the middle of a word, hit ‘bgUw’ (back, global, Upcase, word). If you are somewhere in a sentence, hit ‘(gU)’ (back to start of sentence, global, Upcase, end of sentence). You can make everything lowercase by swapping a ‘u’ for the ‘U’.
I’m the server guy? How do you figure?
About the server thing, turns out you just need to call vim from the commandline with –servername [whatever] option. I’m not sure why you need to do this to call external tools when connected through SSH but for some reason you do.
I took your hosting the 21st Century Monads to be evidence that you were running a server. But even if I was wrong about that, I was right in assuming you would figure out how to use vim via SSH before I even looked into it!
Nah, I just run their site on the UMass servers. (Hey, it’s educational!) I’m too cheap to pay the costs necessary to run my own server, or even for my own domain name.
I’ve made the habit of hitting Ctrl+C to enter Normal Mode. This is default in most vim builds, and I find it much more intuitive and stable than to remap.
Other than that: Great site! I can’t think of a website that fits my niche interests more precisely than this page (being a Philosophy Major and a computer enthusiast).
Hi Carl,
Glad to hear you find the site interesting. I actually hadn’t realized that Control+C would do that. But that makes sense now that you mention it–the same command kills lots of servers you run in the terminal and whatnot. I guess it is a sort of generic kill button. I can see the appeal of this over a remap, though I think my pinkie prefers the remap option!
Hi Charlie
Is there a way to map the control key to the command key in Mac when I use VIM. I find using the ctrl key difficult and would like to map it to the command key whenever I am using VIM.
Hi Kaarthik, Hmn. I don’t know about that. You might try the stickykey plugin. I haven’t tried it, and it doesn’t do quite what you want, but it looks like you could maybe set it up so that
;ois like pressing the ctrl key. That would prevent you having to hit ctrl (though not in the way you wanted).Here is a thread of people discussing your question. Doesn’t look promising.
My only other suggestion off the top of my head is that you might be able to do this with Viking. The new (or perhaps simply proposed) configuration file looks like it might allow you do remap those keys just in MacVim. But I haven’t tried it so I can’t say for sure.
Let us know how it works out if you solve this!