Navigate / search

Vim – customising

Vim is an excellent text editor even with solely its default settings, however, what makes it to be even more outstanding is the possibility of creating your own runtime configuration settings.

Vim is highly customisable by tons of different settings that I am not going to cover in this post. However, I am going to cover some settings that come handy for developers are used to line numbering auto indentation, highlighted searches and so on.

In order to create customized settings for vim, you need to create a settings file, which is possible by creating a .vimrc file (on Linux and Mac, _vimrc on windows). RC stands for “run command”, which is a common linux convention, and each line in your vimrc file is executed as a command. The .vimrc file should be located in your home directory. If you are unsure which directory is used as home directory by vim, you can use:

echo $HOME

that will show you the location you need.

In your .vimrc file you might want to use comments. Lines starting with ” are not interpreted by vim, so they are comments.

Line numbering:

In order to turn on line numbering you can use the following option:

set number

As I mentioned previously, a vim settings file consists of a set of commands to achieve the settings we want for vim so you can just put the commands into your .vimrc file. You can use set nu as well, if you want a command to be as short as possible. It will just do the same.

Search highlighting

Who does not like search highlighting? I definitely like it, so I do recommend to include the following vim command to enable search highlighting:

set hls

If you want to highlight the matched strings as you type you might want to include the following into your .vimrc file: set incsearch

Auto and Smart indentation

For developers to use auto and smart indentation is a must. Smart indentation extends auto indentation and will indent automatically when you are writing a code. (In case of code blocks you perhaps want to indent a block with more spaces then a method header)

To turn those features on you simply need to include the following two commands into your .vimrc file:

set ai
set si

Set background theme

set bg=light
set bg=dark

Check whether an option is set or not

When you are working with vim and are curious if an option is set you can use the same command as you would set the option with a question mark at the end. For example: set ai?

If the result say the name of the option it is allowed, however, if you get no{optionName} as a response (with no prefix) that means the option is not allowed.

Customising settings

Vim has a large variety of settings you can use to customize vim.

You can find out more about the possible options on the official website of vim:

Creating your own vim settings, you can improve your productivity with vim or just make it to be more developer friendly. (Although, it is developer friendly as it is, always was)

The following vim settings file is an example how you can put the commands above together and combine with some more to customize vim.

If you copy paste and receive any errors you need to pay attention to the ” character to indicate comments for vim.


" Line numbering
set number
" Search highlighting
set hls
" Highlight the matched strings when I'm typing
set incsearch
" Show the cursor position. Which line, 
" percentage of the file...
set ruler
" Show incomplete command
set showcmd
" For command completion shows a wild menu of options
set wildmenu
" Show always the defined number of rows 
" when I'm scrolling down.
set scrolloff=5
" Always creates a backup file automatically before save
set backup
" Makes the linebreakes readable. Adds some right padding.
set lbr
" Auto indentation and Smart indentation for coding. 
" Align automatically when I'm typing and hit enter after a block etc.
set ai
set si
" Colour scheme
colorscheme desert
" Enable syntax
syntax on
" Hidden mode for buffers to allow working on 
" multiple files without saving them
set hidden

Leave a comment