81

I see one of these two lines in .vimrc files. This one seems to be most common:

filetype plugin indent on

But how does it differ from this line:

filetype indent on

I've found documentation for the latter, but I'm still confused.

2
  • 3
    side tip: you can do :filetype to show the filetype settings.
    – wisbucky
    Commented Jun 17, 2018 at 1:25
  • side tip: filetype plugin indent on is included in Tim Pope's vim-sensible.
    – icc97
    Commented Jul 11 at 12:41

1 Answer 1

94

filetype plugin indent on is like a combination of these commands:

filetype on
filetype plugin on
filetype indent on

It turns on "detection", "plugin" and "indent" at once. You can check for yourself by reading :help :filetype-overview.

Detection

What does filetype "detection" do? From the docs:

Each time a new or existing file is edited, Vim will try to recognize the type of the file and set the 'filetype' option. This will trigger the FileType event, which can be used to set the syntax highlighting, set options, etc.

This is less confusing if you realise that the filetype command is distinct from the filetype option. (The command :filetype..., the option: :set filetype...)

Plugin

What does the "plugin" part do? From the docs:

This actually loads the file "ftplugin.vim" in 'runtimepath'.

The result is that when a file is edited its plugin file is loaded (if there is one for the detected filetype).

The file being loaded is not necessarily named ftplugin.vim, it could be ftplugin/html_example.vim for instance.

Indent

What does the "indent" part do? From the docs:

This actually loads the file "indent.vim" in 'runtimepath'.

The result is that when a file is edited its indent file is loaded (if there is one for the detected filetype). indent-expression

Again, the file may not be named indent.vim, it could be named indent/html_example.vim for instance.

2
  • 3
    to make it clear, the name of the file should correspond to the 'filetype' for which is is going to be activated, e.g. either <type>/foobar.vim (a subdirectory per filetype) or <type>_foobar.vim or simply <type>.vim where <type> corresponds to the actual filetype Commented Nov 7, 2016 at 11:10
  • @ChristianBrabandt Maybe your words can be added to the answer. It's an important point to make the answer complete. Commented Mar 9, 2023 at 15:45

Not the answer you're looking for? Browse other questions tagged or ask your own question.