1

I've a project where I work on OpenGL Shaders.

I downloaded the glsl syntax file and installed it on my computer (a personal folder) and then added the following auto-load line to my .vimrc:

au BufNewFile,BufReadPost   *.shader,*.frag,*.vert,*.fp,*.vp,*.glsl   so $HOME/vim/glsl.vim

When I first load one of my '*.shader' file, I get the syntax highlighting as expect. The second time (i.e. say I loaded two files, I do :n and then :N), the highlighting is non-existent.

The syntax variable is properly set, syntax=glsl, but the text is just plain black on white.

The glsl.vim file has just two things that could cause a problem:

" near the start
if exists("b:current_syntax") && b:current_syntax == "glsl"
  finish
endif

...

" near the end
if !exists("b:current_syntax")
  let b:current_syntax = "glsl"
endif

I tried to remove the && b:current_syntax == "glsl", because other syntax files do not have that. No difference.

Then I tried to remove the if !exists("b:current_syntax") near the end, and again, no difference.

All my other syntax files work as expected, so I'm not too sure why this one would have such a problem. Everything get colors (my .h and .cpp files, CMakeLists.txt, .sh, etc.) except those *.shader files outside of the first load.

1 Answer 1

2

I downloaded the glsl syntax file and installed it on my computer (a personal folder)

Where did you install the syntax file? Make sure it's located in your ~/.vim/syntax/ directory.

and then added the following auto-load line to my .vimrc:

The :source command is wrong in this context:

au BufNewFile,BufReadPost   *.shader,*.frag,*.vert,*.fp,*.vp,*.glsl   so $HOME/vim/glsl.vim
                                                                      ^-------------------^
                                                                                ✘

It should be a :setfiletype command:

au BufNewFile,BufReadPost   *.shader,*.frag,*.vert,*.fp,*.vp,*.glsl   setf glsl
                                                                      ^-------^
                                                                          ✔

Have a look at the $VIMRUNTIME/filetype.vim file.

1
  • Great! That works! I guess it's time for me to upgrade my .vimrc... I just did a copy/paste from my other entries in that file and I thought it was working, but maybe not. Apr 3, 2021 at 18:23

Your Answer

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

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