Vim Examples: Configuration and the vimrc file

Last updated:
Table of Contents

WIP Alert This is a work in progress. Current information is correct but more content may be added in the future.

Show line numbers

:set number in NORMAL MODE

or add this to .vimrc:

set number

Use spaces for tabs

To use spaces for tabs, and have tabs be 4 columns wide, use these configurations1:

:set softtabstop=4 shiftwidth=4 expandtab

or add this to .vimrc:

set softtabstop=4
set shiftwidth=4 
set expandtab

Enable syntax highlighting

:syntax on

or add this to .vimrc:

syntax on

Enable backspace in insert mode

Add this to .vimrc:

set backspace=indent,eol,start

Add file type specific configuration

If you already have other configurations in .vimrc, this will override configurations for the specific file type only.

Example: tab and indent configuration for .py files only:

(Add to .vimrc):

autocmd FileType python setlocal shiftwidth=2 softtabstop=2 expandtab

1 Here is an explanation of each configuration option: expandtab causes vim to write spaces (instead of a '\t' character) when you hit the key on your keyboard. tabstop controls how many columns will an existing '\t' character take. softtabstop controls how many columns will an added '\t' character take (only if you don't enable expandtab) shiftwidth controls how many columns to use for automatic indenting.


Dialogue & Discussion