19

I'm trying to use the vim-coffee-script plugin https://github.com/kchmck/vim-coffee-script but its not detecting a test file as a coffeescript filetype. However when I do it manually

:set ft=coffee

it works. What's going on?

.vimrc and test.coffee https://gist.github.com/911087

noli
  • 15,927
  • 8
  • 46
  • 62
  • 2
    Did you install the ftdetect part of the plugin as well? coffee.vim is the part that does this, as you can see: `autocmd BufNewFile,BufRead *.coffee set filetype=coffee` – Cascabel Apr 09 '11 at 04:07
  • Thanks! figured it out though.. it was added as a git submodule, so everything was present, but ftdetect wasn't getting loaded. The question was more along the lines of, why wasn't it getting loaded.. but now it is. Thanks – noli Apr 09 '11 at 04:09

3 Answers3

21

I figured it out.. I had to force reloading of the filetype by setting

filetype off
filetype on

Specifically, I had to do this AFTER running

syntax on

This is mostly explained in the pathogen readme

http://www.vim.org/scripts/script.php?script_id=2332

noli
  • 15,927
  • 8
  • 46
  • 62
  • Huh. I don't use pathogen, but that seems odd. If you just dump all of those files into the right directories, it'll work all by itself, no need for any vimrc trickery. – Cascabel Apr 09 '11 at 04:14
  • 1
    Dunno what to say.. its certainly something subtle.. but I git submoduled the vim-coffee-script repo, and it didn't work.. with that change it did. That said, its probably a bug in my previous .vimrc configuration that I never had to deal with before... – noli Apr 09 '11 at 04:54
  • 1
    @Jefromi I just switched from Pathogen to Vundle and saw the *introduction* of this bug. Using noli's solution fixed the bug for me. – Eric Hu Mar 05 '13 at 01:09
  • 1
    @noli bro... saved my sanity... I almost switch to sublime/textmate/alternative... (just kidding) but seriously... thanks! – thelastinuit Apr 14 '16 at 18:53
11

Noli's solution worked for me sometimes. At other times or for other filetypes, it broke. This was infuriating me.

The solution is to move syntax enable to the bottom of vimrc.

Explanation: Following noli's logic a little further, I checked out the pathogen docs on Github. One thing caught my eye

execute pathogen#infect()
syntax on
filetype plugin indent on

Everything is turned on after plugins are installed. I noticed this wasn't the case in my vimrc, so I moved syntax and filetype to the bottom of my vimrc. Problem solved (so far)

Eric Hu
  • 18,048
  • 9
  • 51
  • 67
  • Thanks, super helpful. I had to do BOTH your solution and noli's solution to get it to work. Specifically, I had to include `filetype off` just before `filetype plugin indent on`. – Jack Senechal Aug 09 '13 at 23:50
  • For me this started happening after I switched to Vundle. I realized the `syntax` and `filetype` lines were before all the `Bundle` lines, so I moved them to after and things started working again. – Rufo Sanchez Oct 14 '13 at 14:03
  • Eric Hu's solution worked for me too. I didn't have to move `syntax on` all the way to the bottom, moving it to the line after `filetype plugin indent on` was sufficient. – dmoench Dec 13 '13 at 02:45
4

I tried all the proposed solutions here, but no one worked for me. The solution that worked for me is to add the following snippit to the ~/.vimrc file

syntax on
filetype on
au BufNewFile,BufRead *.coffee set filetype=coffee

and problem solved.

Nafaa Boutefer
  • 2,169
  • 19
  • 26
  • Re. that `au`-tocommand - the thing is that [`vim-coffee-script` should do this for you](https://github.com/kchmck/vim-coffee-script/blob/master/ftdetect/coffee.vim) - there _should_ be no need to add this. However.., I found that inserting it into my `.vimrc` before a `:autocmd!` line didn't help one bit; but inserting after it, did!. Then removing that `:autocmd!` line altogether instead, _also_ fixed it for me - I have no idea hat that line was meant to do, but I have seen no ill effects from its removal so far. – cueedee Mar 24 '23 at 14:55