How to customize Vim using vimrc file

Vim is a command line editor which is an improved version of Vi editor.
This is a very light-weight and powerful editor which allows lots of customizations via plugins.
This is an open-source editor which is available on almost all operating systems.

Let’s look into some basic configurations which should be done to unlock true vim’s potential.

Must have Vim configurations

When Vim is installed, a config file is created with name “.vimrc” (in some os by default these are not created), which contains all the configurations that will be used by vim editor.

In order to customize vim according to our need, this “.vimrc” file needs to updated. Let’s have a look into some basic vim customizations and it’s usage.

Vim SettingsUsage
set nocompatibleThis will disable compatibility with legacy Vi editor.
filetype onThis will enable Vim auto file type detection. Once Vim detect the file types, then it can trigger filetype events such as syntax highlighting, set options etc.
filetype plugin onThis will enable vim to load plugins based on the file type.
filetype indent onThis will allow vim to apply indentation based on file type.
syntax onThis will enable vim to provide syntax highlighting.
color desertThis will set the color scheme of vim.
set numberThis will enable vim to show line numbers.
set cursorlineThis will enable vim to highlight the line on which cursor is placed.
set cursorcolumnThis will enable vim to highlight the column on which cursor is placed.
set shiftwidth=4This will set shift width of 4 places.
set tabstop=4This will set tab width of 4 places.
set expandtabThis will enable vim to use space characters instead of tabs.
set nobackupThis will configure vim to not save any backup files.
set scrolloff=10This will enable Vim to keep cursor in middle of screen. This setting tells vim to keep configured number of lines above and below the cursor.
set nowrapThis will set vim to disable wrapping of lines. This will allow vim to have long lines.
set incsearchThis will allow vim to highlight incrementally matching characters as search string is typed.
set ignorecaseThis will set vim to ignore case of the words while searching.
set showcmdThis will enable vim to show partial command typed in the last line of the screen.
set showmodeThis will enable vim to show the mode of the vim in the last line.
set showmatchThis will enable vim to show the matching words while searching.
set hlsearchThis will enable vim to highlight all the searched items.
set history=500This will set vim to remember number of lines.
set mouse=aThis will enable vim to use mouse. This will only work in few terminals.
 
vimrc most useful configurations

Let’s have a look into sample .vimrc file which is created with above settings. This file can be directly copied and used.

" Disable compatibility mode with vi to avoid unexpected issues.
set nocompatible

" This will enable Vim auto file type detection. 
filetype on

" This will enable vim to load plugins based on the file type.
filetype plugin on

" This will allow vim to apply indentation based on file type.
filetype indent on

" This will enable vim to provide syntax highlighting.
syntax on

" This will set the color scheme of vim.
color desert

" This will enable vim to show line numbers.
set number

" This will enable vim to highlight the line on which cursor is placed.
set cursorline

" This will enable vim to highlight the column on which cursor is placed.
set cursorcolumn

" This will set shift width of 4 places.
set shiftwidth=4

" This will set tab width of 4 places.
set tabstop=4

" This will enable vim to use space characters instead of tabs.
set expandtab

" This will configure vim to not save any backup files.
set nobackup

" This will enable Vim to keep cursor in middle of screen.
" This setting tells vim to keep configured number of lines above and below the cursor.
set scrolloff=10

" This will set vim to disable wrapping of lines. This will allow vim to have long lines.
set nowrap

" This will allow vim to highlight incrementally matching characters as search string is typed.
set incsearch

" This will set vim to ignore case of the words while searching.
set ignorecase

" This will enable vim to show partial command typed in the last line of the screen.
set showcmd

" This will enable vim to show the mode of the vim in the last line.
set showmode

" This will enable vim to show the matching words while searching.
set showmatch

" This will enable vim to highlight all the searched items.
set hlsearch

" This will set vim to remember number of lines.
set history=500

" This will enable vim to use mouse. This will only work in few terminals.
set mouse=a

Let’s have a look into sample to show how these settings work.

vimrc configuration example
vimrc configuration example

Leave a Reply

Your email address will not be published. Required fields are marked *