Search code examples
vimorganization

autocmd FileType vs ftplugin


What is the difference between placing:

autocmd FileType ruby setlocal ts=2

in my ~/.vimrc and placing:

setlocal ts=2

in ~/.vim/ftplugin/ruby.vim?

If there is no difference, where should I place commands that are specific to one filetype?


Solution

  • As far as I know, there isn't really a difference between the two.

    I prefer to put commands like that in ftplugin and keep my main .vimrc language-agnostic… But there are no hard-and-fast rules. An advantage to keeping it in your vimrc would be that your vim settings would be easier to move around (ex, you could get all your vim settings on a new machine by simply copying your .vimrc, instead of .vimrc + .vim). Obviously putting them in your .vimrc will also have a minor performance penalty (ie, they will be loaded + executed for every file, not just ruby files)… But I wouldn't really worry about that.