Vim Configuration

Basic Configuration

To get all of Vim's useful features (and replace the horrible default settings):
  1. Edit your ".vimrc" file.
    $ cd
    $ vim .vimrc
  2. Now you're in Vim in command mode. Execute the following commands:
    :r $VIMRUNTIME/vimrc_example.vim
This will:

Tab Configuration

To set the tab width to 2 or 4 characters (the default is 8 characters, which is too big), add the following commands to the bottom of your .vimrc file:

" Indentation settings
set tabstop=2
set shiftwidth=2

To make Vim insert spaces ("soft tabstops") instead of real tabs ("hard tabstops"), add the following:

" use soft tabstops
set expandtab

Which should you do? Honestly, it's a personal preference. You can change the width of real tabs by changing your editor's settings, while spaces mean that anyone can view your file as intended without changing any settings.

IMPORTANT: makefiles require real tabs. If you choose to use spaces for your code, you will need to temporarily change your settings when you edit a make file. Use the following commands while in Vim:

:set expandtab
:set noexpandtab

Or, you can just use another editor, like Nano (which also defaults to real tabs) when editing makefiles.

Last updated 12/17/12