The vimrc File

Posted by Derek Wyatt on August 20, 2009
What the vimrc file is for and how to get it going.

The Heart of Your Vim Setup

Your vimrc file is an incredibly powerful, incredibly useful thing. Anything you can do in command-line mode you can do in your vimrc file. This makes it possible to make settings (e.g. :set textwidth=80) in the command-line mode and then make them permanent in your vimrc file by just doing the exact same thing but in a file instead of in the running Vim session.

Where it is

Depending on what operating system you’re running on the vimrc file will be in a slightly different place. However, no matter where it actually is you can reference it from within Vim using the $MYVIMRC variable.

On Unix (Linux, OS X, whatever…)

On these operating systems, the vimrc file defaults to being in your home directory at ~/.vimrc. If it’s not there then just create it by editing it and saving it.

On Microsoft Windows

On all of the MS Windows variants you’ll also find this in your HOME Directory but most people don’t know where that is ;). I’m not going to try and tell you where it is, specifically and leave that up to Wikipedia’s Home Directory Page. In general however it is one directory up from the directory that contains your “Documents” (e.g. “My Documents” in Windows XP). The major difference is that it’s named slightly differently than it is in Unix: it’s named _vimrc.

What’s it for?

Everything. Ok, that’s not strictly true but at this stage in the game it’s more than sufficient to look at it that way. In practice you’ll find that plugins and many other types of file type specific configuration will make use of Vim’s extensive capabilities in its runtime structure, outside of the vimrc file but that sort of thing comes… later.

Generally you should think of your vimrc file as holding your own personal option settings, mappings, functions, commands and whatever else you need to customize Vim for your personal use.

Specific Examples

Here we’ll get more specific and actually look at some real contents of a vimrc file.