Vim Examples: Configuration and the vimrc file

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 produce 4 whitespace characters when you hit the TAB key for indentation, use this configuration1:

  • use within vim:

    :set softtabstop=4 shiftwidth=4 expandtab
    
  • or add this to the .vimrc configuration file:

    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

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

.vimrc VS .vim directory


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.


References