VIM - Config - Indentation - File type based indentation

This type of indentation is the most flexible, as it allows users to customize indentation per file type.

Enable this type of automatic indentation with the following command:

filetype plugin indent on

NOTE: This command will use indentation scripts located in the indent folder of the vim installation.


Different settings for different file types


For instance, the indentation scripts for C and C++ file types properly set the cindent option, and there are very competent indentation scripts for Ruby, Perl and many other languages and file types.

File type based indentation even works correctly with Makefiles without interference!

WARNING: If you plan on using file type based indentation, do not set smartindent or cindent.

  • You may still set autoindent, since it does not interfere.

The vimrc_example.vim that ships with Vim enables filetype based indentation:

if has("autocmd")
  " Enable file type detection.
  " Use the default filetype settings, so that mail gets 'tw' set to 72,
  " 'cindent' is on in C files, etc.
  " Also load indent files, to automatically do language-dependent indenting.
  filetype plugin indent on
  " ...
endif