Chapter 4Recognizing File Types

In Chapter 3, The Autoload System, we named our mpc playlist’s buffer by giving it the filename mpc.mpdv. With a filename, we now can work with Vim’s filetype support.

Standard Vim supports a lot of different filetypes. We turn on filetype recognition using the :filetype command in our vimrc; usually we set the command like this, which also tells Vim to indent files if it can do that for the filetype:

 
filetype​ plugin indent ​on

With this set, Vim can recognize a file extension or line of code in a file and then set indentation levels, define custom commands, and enable the correct syntax highlighting.

Filetype recognition is buffer-local; that is, Vim sets the filetype option separately for each buffer. ...

Get The VimL Primer now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.