How do I set different options for different types of files?
You can create filetype plugins to set different options for different types of files. You should first enable filetype plugins using the command:
:filetype plugin on
A filetype plugin is a vim script that is loaded whenever Vim opens or creates a file of that type. For example, to ensure that the ‘textwidth’ option is set to 80 when editing a C program (filetype ‘c’), create one of the following files:
~/.vim/ftplugin/c.vim (Unix) %HOME%\vimfiles\ftplugin\c.vim (Windows)
with the following text in it:
You can also use autocommands to set specific options when editing specific type of files. For example, to set the ‘textwidth’ option to 75 for only *.txt files, you can use the following autocmd:
autocmd BufRead *.txt setlocal textwidth=80