Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Overriding MacVim's default filetype.vim when assigning filetypes

In the default filetype.vim that comes with MacVim, I have the following:

au BufNewFile,BufRead *.erb,*.rhtml setf eruby

I installed MacVim using Homebrew, and I've installed Janus. Following the instructions from Janus, I've created ~/.vimrc.local to store my local customizations. I want to set the filetype for *.html.erb files to html.eruby.eruby-rails, so I added the following line to ~/.vimrc.local.

autocmd BufNewFile,BufRead *.html.erb setf html.eruby.eruby-rails

However, it appears that the filetype is still being selected by MacVim's default filetype.vim instead of picking up my change in ~/.vimrc.local.

What do I need to do differently, so as to have MacVim properly designate *.html.erb files as filetype html.eruby.eruby-rails without modifying the default filetype.vim?

like image 964
Matthew Rankin Avatar asked Feb 23 '11 14:02

Matthew Rankin


People also ask

How do I change the filetype in vim?

As other answers have mentioned, you can use the vim set command to set syntax. :set syntax=<type> where <type> is something like perl , html , php , etc. There is another mechanism that can be used to control syntax highlighting called filetype , or ft for short.

How does vim determine filetype?

vim is read from directories in the runtime path. The first match which executes :setf will set the filetype for the file Vim is creating or reading. If no rules execute :setf then additional filetype. vim files will be read.


2 Answers

Change setf in your autocmd to set ft=. If you take a look at :help setf it says it will not set the filetype if it has already been set elsewhere.

like image 80
Randy Morris Avatar answered Sep 22 '22 01:09

Randy Morris


Well, I tried the following and it seems to work:

autocmd FileType eruby set ft=html.eruby.eruby-rails

However, if I understand correctly, this is changing all files that the default filetype.vim designates as eruby to a filetype of html.eruby.eruby-rails.

like image 45
Matthew Rankin Avatar answered Sep 18 '22 01:09

Matthew Rankin