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 Settings | Usage |
---|---|
set nocompatible | This will disable compatibility with legacy Vi editor. |
filetype on | This 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 on | This will enable vim to load plugins based on the file type. |
filetype indent on | This will allow vim to apply indentation based on file type. |
syntax on | This will enable vim to provide syntax highlighting. |
color desert | This will set the color scheme of vim. |
set number | This will enable vim to show line numbers. |
set cursorline | This will enable vim to highlight the line on which cursor is placed. |
set cursorcolumn | This will enable vim to highlight the column on which cursor is placed. |
set shiftwidth=4 | This will set shift width of 4 places. |
set tabstop=4 | This will set tab width of 4 places. |
set expandtab | This will enable vim to use space characters instead of tabs. |
set nobackup | This will configure vim to not save any backup files. |
set scrolloff=10 | 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 nowrap | This will set vim to disable wrapping of lines. This will allow vim to have long lines. |
set incsearch | This will allow vim to highlight incrementally matching characters as search string is typed. |
set ignorecase | This will set vim to ignore case of the words while searching. |
set showcmd | This will enable vim to show partial command typed in the last line of the screen. |
set showmode | This will enable vim to show the mode of the vim in the last line. |
set showmatch | This will enable vim to show the matching words while searching. |
set hlsearch | This will enable vim to highlight all the searched items. |
set history=500 | This will set vim to remember number of lines. |
set mouse=a | This will enable vim to use mouse. This will only work in few terminals. |
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.