DEV Community

Connor Bode
Connor Bode

Posted on

Filetype settings in .vimrc

Languages all have different settings. The most common one is indentation style.

How do you set VIM up to automatically use the settings you prefer, for your language?

Open up .vimrc (either a local one or your ~ one). Then add the following:

autocmd FileType html setlocal <settings_you_want_to_set>

For example, I've just added:

autocmd FileType yaml setlocal ts=2 sw=2 expandtab

If you don't know the FileType, you can open up a file of the type in question (for me it was a .yml) and run :set filetype?


Hopefully this was useful for you!

Follow me on dev.to or on Twitter @connorbode for more VIM, Linux, and other tips as I discover new things!

Top comments (3)

Collapse
 
chsanch profile image
Christian Sánchez

Nice, but if you have more settings for different file types, maybe is better put them into a filetype plugin or ftplugin, I would recommend to check this very useful article vimways.org/2018/from-vimrc-to-vim/

Collapse
 
connorbode profile image
Connor Bode

I'd argue that multiple files are harder to port over if you're working on many different servers.

¯_(ツ)_/¯ different strokes for different folks

Collapse
 
captainawesomedi profile image
Di Wu

Very useful! needed this very much. Cheers!