Introduction to Vim

Configuration

Editing a very long configuration file and you can not find the line you have to change? Why not simply search for it? Users who have experience with graphical editors, might miss some features which make working more comfortable. Now it is time to change this.

Overhaul Vim

Tab completition is available throughout Vim. This minimizes the amount of typing for longer commands, decreases the error rate and can show you new options. Simply hit <TAB> the next time you type a longer command.

Line numbering is a feature which makes programming easier. It can be enabled with the :set number command and disabled by :set nonumber. Another way to make programming with Vim easier is to enable syntax highlighting. This is done with :syntax on and turned off by :syntax off. If you do not like the colors Vim uses, change them! You can select between different colorschemes by issueing :colorscheme COLORSCHEME. Use <TAB> to switch through the available colorschemes.

While these options are nice when programming or editing configuration files, there are other use scenarios with Vim. You could use it to write your emails or your documents and presentations. When doing so you are not so interested in syntax highlighting, but rather your spelling. Spell checking can be turned on with :set spell. Other languages than English are available, you have to download them first. Then you can select the language with :set spell spelllang=LANG, where LANG is the language.

Make it last

All these changes will be reverted the next time you start Vim. To always issue all these commands by hand can be quite annoying. Vim provides you with the possibility to put options in the .vimrc file in your home folder. These options will be loaded whenever Vim starts.

This a very basic .vimrc file, which should get you started. Feel free to improve it! You can download the file over here.

" standard settings
set nocompatible
set ml

" enable colors
set t_Co=256
syntax on
set background=dark

" make a tab be 2 spaces wide
set tabstop=2
set shiftwidth=2
filetype plugin indent on

" linenumber functions
set number
set nuw=6

function! g:ToggleNumberMode()
	if(&nu == 0)
		set number
	else
		set nonumber
	endif
endfunc

""" Keybindings
" toggle paste mode with F2
set pastetoggle=
" toggle line numbers with CTRL + l
imap  :call g:ToggleNumberMode()i
nmap  :call g:ToggleNumberMode()