14

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?

Zameer Manji
  • 2,908
  • 4
  • 28
  • 39
  • It is not a good example because `g:rubycomplete_buffer_loading` is a *global* variable that is to be put into vimrc without preceding `autocmd Filetype ruby`. – ZyX Oct 23 '11 at 06:26

1 Answers1

10

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.

David Wolever
  • 130,273
  • 78
  • 311
  • 472
  • Thanks for the answer. I have been placing code in `ftplugin` and i think I will continue to do so to keep my `.vimrc` simple. – Zameer Manji Oct 23 '11 at 13:15
  • How do you know there is a "performance penalty"? Could you explain how both approaches work (implementation details)? – ma11hew28 Sep 14 '18 at 16:16