Sign up ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

I'm using vim to try a template system named handlebars, and I installed a vim plugin to get some syntax-highlighting for *.handlebars. I can get coloration if I do this : :set filetype=handlebars, but when I open a template, it is monochrome. My .vim folder looks like this:

|-- autoload
|   `-- pathogen.vim
|-- bundle
|   |-- handlebars
|   |   |-- example.handlebars
|   |   |-- ftdetect
|   |   |   `-- handlebars.vim
|   |   |-- ftplugin
|   |   |   `-- handlebars.vim
|   |   |-- indent
|   |   |   `-- handlebars.vim
|   |   |-- MIT-LICENSE
|   |   |--
|   |   `-- syntax
|   |       `-- handlebars.vim

What can I try to get automatic filetype detection?

Here is the content of handlebars.vim :

if has("autocmd")
  au BufNewFile,BufRead *.handlebars,*.hbs set filetype=handlebars

I think I have autocmd, because :autocmd outputs something.


Here is the content of my .vimrc :

call pathogen#runtime_append_all_bundles()
call pathogen#helptags()
syntax on
set softtabstop=2 
set shiftwidth=2
set tabstop=2
set expandtab
set number
set background=dark
set laststatus=2 
set statusline=%<%f\ %h%m%r%{fugitive#statusline()}%=%-14.(%l,%c%V%)\ %P
colorscheme solarized
filetype on
filetype plugin on

Here is my .vim folder if someone wants to take a look at it :

share|improve this question

2 Answers 2

First. When editing one of your .hbs, or .handlebars files, issue :set ft? in vim, and see if your filetype is being detected.

If you don't see filetype=handlebars, try setting :filetype on in your .vimrc file and test again.

If that doesn't work, you may need to put a filetype.vim file in your .vim directory.

if exists("did_load_filetypes")
augroup filetypedetect
  au! BufRead,BufNewFile *.hbs,*.handlebars setf handlebars
augroup END

save this as $HOME/.vim/filetype.vim

  • that's really 'filetype.vim', not handlebars.vim, in the .vim directory.

Then try that :set ft? again, in a new vim session.

Your handlebars.vim file, in the $HOME/.vim/ftplugin directory should contain the syntax rules for whatever you want displayed when you're editing a .hbs file, like this one here.

share|improve this answer
Thanks for your answer, it was useful. I updated my question with my .vimrc , which already had the filetype on directive in it (without the colon, but I think that's normal, isn'it?) putting the filetype.vim in my .vim folder did the trick! Now what if I want to add another coloration plugin? Should I add more things in this file? Or was this all for debugging purposes and are you going to give me a better solution? – greg0ire Oct 2 '11 at 9:57
I added a link to my .vim folder on github in my question, so now you can have a look at it. – greg0ire Oct 2 '11 at 10:18
To add new filetypes, just put the $filetype.vim file in your .vim/ftplugin/ directory, and then add another au! line to your .vim/filetype.vim file, between the augroup filetypedetect and augroup END lines. – Tim Kennedy Oct 2 '11 at 13:05
I think it is the purpose of this file :… The code you made me write in filetype.vim looks like a duplicate of it. What I would like is have this piece of code run. I think it is the purpose of the filetype plugin on directive, isn't it? – greg0ire Oct 2 '11 at 13:09
I actually meant this file :… – greg0ire Oct 2 '11 at 13:17
up vote 1 down vote accepted

I finally found the answer myself. The two pathogen calls at the top of my .vimrc file do something that is not sufficient to take coloration into account. Using this call did the trick:

call pathogen#infect()
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.