Frequently Asked Question

What is the .vimrc file and what should go in it?

~/.vimrc is Vim's configuration file: a plain text file in your home directory containing Vim's own scripting language (Vimscript). Vim reads it every time it starts and runs the commands in order. Neovim uses ~/.config/nvim/init.vim or ~/.config/nvim/init.lua for the same purpose. Each line is a regular Vim command of the kind you could type after :, set number is identical to typing :set number after launching.

A sensible starter .vimrc covers four areas: appearance (set number, syntax on, set showmatch), search behaviour (set ignorecase smartcase incsearch hlsearch), indentation (set expandtab tabstop=4 shiftwidth=4), and integration with the rest of the system (set clipboard=unnamedplus, filetype plugin indent on, set mouse=a). Comments start with a double quote. Inside Vim, :help option documents any setting in detail.

It is common for a .vimrc to grow over the years until it is hundreds of lines long and you cannot quite remember why each one is there. Many users version their dotfiles in Git and copy them onto new machines. The advice that holds up best: keep it small, add a line only when you can explain why, and try Vim's defaults first, Vim 8 and Neovim have much better out-of-the-box behaviour than they did a decade ago.

Further reading and video