Get going with vim

by Gregor Uhlenheuer on June 26, 2013

To my mind vim is probably the best editor for programming and text editing. However there are various helpful settings that are not set by most distribution’s default installations you may want to know to get the most out of your vim editing experience. Moreover there are a bunch of vim scripts that should not miss in your vim runtime files.

vimrc

The following settings are not meant to be a fully functional or useful vim configuration but more of a collection of snippets you could consider adding to your own .vimrc. In my opinion you should not blindly copy other people’s vim configuration files without understanding every single setting itself anyway.

However you can find a copy of my .vimrc on github for reference or inspiration.

Settings

Basic editing

The most important non-default setting is called hidden which enables you to switch between buffers without having to save in between. This is very important in order to understand vim’s concept of buffers and tabs which may appear somewhat different compared to other popular text editors. See :h buffers and :h tabpage for further information.

" disable VI compatibility
set nocompatible

" enable buffer switching without having to save
set hidden

" allow backspace in insert mode
set backspace=indent,eol,start

" always activate automatic indentation
set autoindent

Display

" display statusline even if there is only one window
set laststatus=2

" visually break lines
set wrap

" display line numbers
set number

" line numbers as narrow as possible
set numberwidth=1

Searching

" turn on highlight search
set hlsearch

" ignore case in search when no uppercase search
set incsearch
set ignorecase
set smartcase

Starting from a basic set of options you can incrementally improve or extend your vim configuration by exploring vim’s options. For one you can get help for every setting by invoking :h :<optionname>. Moreover you can get a complete list of available options via :options.

Mappings

Find a few very basic key mappings you may find useful as well:

" redraw screen and remove search highlights
nnoremap <silent> <C-l> :noh<CR><C-l>

" yank to end of line
nnoremap Y y$

" use Q for formatting
noremap Q gq

" easier navigation on wrapped lines
nnoremap j gj
nnoremap k gk

Plugins

You may find a few of my favourite plugins below:

Resources

This post is tagged with vim, programming and linux