Vim - Configuration

Updated: 2020-06-29

Where to Set Configurations

Configurations can be set in two ways:

Option 1: one of the vimrc file

  • Global:/usr/share/vim/vimrc
  • Personal:~/.vimrc

personal overrule global

Option 2: inside vim

In normal mode, press : then type in commands to config the current session. Once exit the configs will be lost.


Enable syntax highlight

:syntax on

Set tab width

:set ts=4

Set shiftwidth(when using command like ">>")

:set shiftwidth=4

Expand tab to space

:set expandtab


:help 'statusline'
:set statusline format

:set statusline=%F%m%r%h%w\ [FORMAT=%{&ff}]\ [TYPE=%Y]\ [ASCII=\%03.3b]\
[HEX=\%02.2B]\ [POS=%04l,%04v]\ [%p%%]\ [LEN=%L]

show statusline

:set laststatus=2

hide statusline

:set laststatus=0

remove the menu

:set guioptions-=m

remove the toolbar

:set guioptions-=T

Set cursor horizontal and vertical highlights

:set cursorline
:highlight CursorLine guibg=lightblue ctermbg=lightgray
:set cursorcolumn


:set nocursorline :set nocursorcolumn

Show/hide line number

:set number
:set numberwidth=XXX
:set nonumber

spell check

:set spell
:set spelllang=de
:set spelllang=en,da,de,it
:set spellsuggest=X


:set compatible

Change fonts: only work for gvim, space need to be escaped

:set guifont=Courier\ 14

With alternative:

:set guifont=Courier\ New\ 12, Arial\ 10

show font list

:set guifont=*

set font for certain type of files: add to vimrc

autocmd BufEnter *.txt set guifont=Arial\ 12

Change Color Scheme:

:colorscheme ColorScheme

find installed schemes in

:colorscheme default

traverse installed schemes, press tab button after the whitespace

:colorscheme <tab>


:highlight MyGroup ctermbg=red guibg=red gctermfg=yellow
guifg=yellow term=bold
  • ctermb: Background color in console
  • guibg: Background color in Gvim
  • ctermf: Text color in console
  • guifg: Text color in Gvim
  • gui: Font formatting in Gvim
  • term: Font formatting in console (for example, bold)


Add syntax file to (e.g. pig.vim)


Add these to ~/.vimrc

augroup filetypedetect
    au BufNewFile,BufRead \*.pig set filetype=pig syntax=pig
augroup END

Example .vimrc

syntax on
set ts=4
set shiftwidth=4
set expandtab
set backspace=2