Monday, 23 March 2009

Configuring Vim

The Vim text editor is available on nearly every OS around (Primarily *nix), and it is popular among heavy text users like programmers. It is configured by modifying the .vimrc file.

The .vimrc file is located here on most OSes -
~/.vimrc

You change settings by writing lines into the file. Vim then checks this file before it runs, and applies any settings in the file. Each setting needs to be on it's own line. You can modify the .vimrc file with any standard text editor like Gedit, Kwrite, or even Vim itself.

These are options that could make your life a bit easier.


syntax on

This will make Vim highlight your text, depending on what programming language you are using. If you don't use Vim for programming, you will probably find no use for this.


set tabstop=x

By default, tabs are 8 spaces, and it is the same on most text editors. Some people (like me) prefer a different amount like 4. The x represents the amount of spaces a tab should be. So, if I wanted my tabs to be 4 spaces, I would add this line -

set tabstop=4


shiftwidth=x

Similar to above, but it applies to reindent operations and automatic C indentation.


set autoindent

This is another feature coders will like. It does what it says on the tin, it automatically indents, for example the line after a {.


set nobackup
set nowritebackup


Vim will backup active files out the box. This is so if Vim dies for some strange reason, you won't lose that much work. Unfortunately, the backups seem to cause conflicts sometimes when reopening files and other things, so it is best to turn this off, and just manually backup when required.


set ruler

This will give some useful information on the bottom line like what line you are on and stuff.


These are just a few options you can modify on the Vim editor. Here is my ~/.vimrc file, in case you want to take a look -

syntax on
set nocompatible
set tabstop=4
set shiftwidth=4
set autoindent
set smartindent
set nobackup
set nowritebackup
set ruler

0 comments:

Post a Comment