Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 594
Zameer Manji Avatar asked Oct 23 '11 01:10

Zameer Manji


1 Answers

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.

like image 143
David Wolever Avatar answered Sep 17 '22 11:09

David Wolever