Aug 30, 2008

Configuration of the Vim Editor

vim editor screenshotVim is a fast and feature-rich text editor. It offers syntax highlighting for many programming and scripting languages, editing by regular expressions, and a lot more. In this post I give first a short introduction to vim then I show how to enable some of its powerful features by default on start of vim.

Introduction to Vim

Vim is free as in beer and speech and was created as an extended version of the vi editor, with many additional features designed to be helpful in editing program source code and the name Vim stands for Vi IMproved. Vim is cross-platform, which means that it works on many different operating systems, including Windows, Linux, and Mac.

Handling of Vim is not completely intuitive, however vim can make you very fast when you edit text as this screencast demonstrates.

Vim gives you great power, which comes at the price of a steep learning curve. There is a tutorial (command :vimtutor), online documentation, you can find many cheatsheets on the internet. For a more accessible interface to vim, there is Cream, a descendant of vim.

The following video offers you a first introduction to the vim editor.

Configuration (vimrc)

In this section I describe my basic configuration for vim. We want to enable some of the powerful features that Vim offers. The initial settings depend on your system. You can check them by opening the file $VIM/vimrc (on Linux this is usually /usr/share/vim/vimrc, type :echo $VIM within vim to find out where you have them).

I want searching with smart case matching, I want to use the mouse to mark text and for jumping with the cursor, and filetype plugins, I want US American spell checking for txt, tex, and HTMLs. I also want an extended status line and have some WYSIWYG with latex which means instant compiling and viewing by pressing ctrl-k.

nocompatiblemost important option. nocompatible prevents vim from emulating the original vi's limitations.
autoindenttells vim to use the previous line's indent level to set the indent level of the new lines.
smartindentlets vim make an educated guess based on the content of the previous line (works for programming code).
tabstopdefines how many spaces correspond to a tabulator.
showmatchtells vim to show you matching opening or closing brackets when you step on a bracket with your cursor.
incsearchvim will search for text as you enter it.
syntax onsyntax highlighting on
filetype plugin indent onload filetype plugins/indent settings
ignorecasecase insensitive
smartcaseif there are capital letters, become case sensitive
wildmenuvim's command line completion
clipboard=unnamedVim yanks into the system clipboard and you can paste into other applications (in linux by middle click)

Try :help options in Vim to see all available options.

The spellfile option is for adding words to your user spell dictionary (move cursor over word and press zg).

Here goes my ~/.vimrc (exported to html by gvim):

set ignorecase smartcase
set nocompatible
set incsearch
set expandtab
set shiftwidth=2
set smarttab autoindent
syntax match Tab /\t/
hi Tab gui=underline guifg=blue ctermbg=blue 
set showmatch
set ru
set mouse=a
filetype indent on
set clipboard=unnamed
filetype plugin on
set wildmenu
autocmd BufNewFile,BufRead *.txt,*.tex,*.html,README set spell spelllang=en_us 
syntax on
set paste
set statusline=%F%m%r%h%w\ [FORMAT=%{&ff}]\ [TYPE=%Y]\ [ASCII=\%03.3b]\ [HEX=\%02.2B]\ [POS=%04l,%04v][%p%%]\ [LEN=%L]
set laststatus=2
:map Q <Nop>
I like especially the status line (Note that ^K has to be entered within vim by pressing three times ctrl-k, and ^M by pressing ctrl-k once and ctrl-m twice). I found the status line in the book Hacking VIM" by Kim Schulz, which explains more about how to personalize vim. When you are programming/scripting and porting code from Windows to Unix it is important to convert carriage returns (CR) to linefeeds (LF) otherwise you'll get errors. The last part of the status line issues therefore a warning in red, if the file format is not unix. I found this hack in the article about conversion between unix and windows with vim at

The last line disables the ex mode.

Further Reading:
In this excellent blog post, the author gives some very useful hints, including code folding and multiple clipboards. Also, you might want to read an introduction to personalization of vim.

More great vim commands you can find at CommandLineFu.

Image Credit:
vim screenshot at wikipedia.


  1. and Lisa told her that she hadn��t been able to finish it. Simpson told her she would like the ending. Over the years Lisa had an on-and-off relationship louis vuitton bags with Simpson, but it would be closer in some ways than the one she had with her father.

  2. Buy POS Systems and POS System Configurator at Attractive Prices

    At Gemini Computers, you may buy POS System configurator, POS System with Monitor, Drawer, Scanner, Keyboard, and CRE POS Software at attractive and affordable prices. You can choose POS Systems according to your desired configurations and budget.

  3. Assertive self, discard negative thoughts and do good. Anxiety only belongs to those who despair.

  4. Maturity is measured not by the age, but of how we respond to a situation of full responsibility dg.
    No absolute honesty in the heart. Feel and follow, then that's where the joy of life we ??will meet.

    Lowongan Kerja PT. Musashi Auto Parts
    Manfaat Bawang Bombay
    Berita lowongan Kerja
    Berita Kesehatan

  5. Video-games are action relax everyone's mind, with games such as Tiny Tanks or Tiny Planes and Tiny Planes Beta will be the attractive game people, in addition to games such as Run 3 unblocked or Run 4 unblocked or hacked unblocked games also very charismatic players. You try to play view, it is very attractive!