11

My ~/.vimrc contains the following line:

au BufNewFile,BufRead *.fsh,*.vsh setf glsl

My ~/.vim/syntax directory contains glsl.vim that works if loaded manually (:setf glsl in Vim), but it doesn't load automatically when editing a file with those extensions. How do I get syntax highlighting for those files automatically? Syntax highlighting works for other files as usual. My Vim version is 7.4 running on Linux Mint.

3
  • 2
    This might be a shot in the dark but: have you tried using the extended form set filetype=glsl instead of setf glsl? Commented Jan 29, 2014 at 18:55
  • 2
    @Nadir Sampaoli: That is not an "extended form," it is a different command. See :help :setf. Commented Jan 29, 2014 at 19:30
  • 2
    @SurvivalMachine: What happens with :e foo.fsh and then :verbose set ft?? How about :verbose au BufNewFile *.fsh? Commented Jan 29, 2014 at 19:33

1 Answer 1

6

I don't think that line can be in your ~/.vimrc. Due to loading order, it may have to be in ~/.vim/filetype.vim instead. Try putting this into that file:

augroup filetypedetect
  au BufNewFile,BufRead *.fsh,*.vsh setf glsl
augroup END
Sign up to request clarification or add additional context in comments.

3 Comments

VIM commands can be in .vimrc. That's the whole point of its existence.
Vim commands can be in .vimrc, but they can also be elsewhere. File type commands are supposed to be in filetype.vim, and I've had issues trying to force it into .vimrc in the past. This is because load order can matter, as implied by this question.
Tried adding it to /usr/share/vim/vim73/filetype.vim. After I put au BufNewFile,BufRead *.fsh,*.vsh setf glsl in ~/.vim/filetype.vim, it worked.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.