In my opinion, the cleanest method of doing this is simply to add the command to a file in your
or for Windows:
This technique is documented in
:help ftplugin-overrule (list item 3), although the context (changing settings) is slightly different.
It offers the following benefits over the autocommand technique described by kapil.
Less code. You just write the Vimscript you want executed. You don't need to code an autocommand and surround it with
autocommand! clear commands.
Less overhead. Vim is already detecting the file type and checking for the existence of the
after/ftplugin/filetype file: why add an additional autocommand that performs the same purpose?
.vimrc. I think it's better to have file-type-specific functionality separated out from my
.vimrc. (Some disagree with this, though: see the disadvantages, below.)
It also has a couple of minor disadvantages:
It only works if you are using Vim's filetype detection. (
However, this is generally one of the first settings that people enable in their .vimrc, and I'd wager that almost all Vim users already have it switched on.
Some people prefer to keep all their config in their