For those with preference for Vim command line text editor for their programming tasks, there’s a few settings that you can tweak to enhance its usability. The config file is usually located in /usr/share/vim/vimrc on Linux and Mac machines, unto which you can add the following lines:
syntax on
This turns on syntax highlighting. This is default on Ubuntu, but Mac users (as of Snow Leopard) will need to add this manually.
set number
This turns on line numbering, which is essential for programmers.
set smartindent
set autoindent
As you may have guessed, this spices up Vim’s indentation a little bit. I’ve noticed that they prevent the cursor from returning to the start of a line when the Return key is pressed. There are also other indenting options, such as cindent, but I find it particularly annoying and never used it.
set shiftwidth=4
set tabstop=4
These set tabstops every 4 characters, which is standard for most programming languages. You may substitute it with other values if preferred.
augroup vimrc_autocmds
au!
autocmd BufRead * highlight OverLength ctermbg=red ctermfg=white guibg=#592929
autocmd BufRead * match OverLength /\%81v.*/
augroup END
This is a temporary solution to the right margin problem with Vim written by cyrilrbt as Vim does not support displaying right side margin. When these 5 lines are added, Vim will highlight the 81st character onwards with the colour scheme of an error message (white font on red background).
Restart Vim and all changes should take effect immediately.
Recent Comments