How to associate files with existing filetype in Vim

Vim has support for many filetypes. If it detects that a file is of a certain filetype, then syntax highlighting and indenting rules of that filetype are applied to the file.

If you have a new file extension that you want to associate with an existing filetype, that is easy to do in Vim. For example, to associate files of type .foo with the filetype .html, add this line to your .vimrc:

autocmd BufRead,BufNewFile *.foo set filetype=html
  • The list of filetypes known to your Vim can be found as described here.
  • Make sure that filetype on is already done before this line in the .vimrc file.

For more info, try :help new-filetype in your Vim πŸ™‚

Tried with: Vim 7.4 and Ubuntu 14.04

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.