How to Have Language-Specific Settings in Vim

I wanted to set up Vim so that Coffeescript files would use 2 spaces for indentation. This was very simple:

  1. Create a file at ~/.vim/ftplugin/<language>.vim where <language> is the language you want to modify. For Coffeescript, this is coffee. The language name you should use is just the file extension.
  2. In this file, add your settings. In my coffee.vim, I have setlocal tabstop=2 and setlocal shiftwidth=2 to make my tabs 2 spaces.
  3. Open up a file in that language and enjoy your language specific settings!

Thanks for reading my post! If you enjoyed it or it helped you, please consider liking/tweeting this page, commenting, or following me on GitHub or Twitter!