4

I tried to change the syntax highlighting, by copying /usr/share/vim/vim74/syntax/html.vim to ~/.vim/after/syntax/html.vim. Then I changed the syntax highlighting file, but I don't see any changes. filetype is set properly, and when I change something in /usr/share/vim/vim74/syntax/html.vim, I can see the changes. Is there anything I need to do to "activate" the after/syntax folder for highlighting?

5

To change the syntax highlighting of a filetype by copying $VIMRUNTIME/syntax/<filetype>.vim to your ~/.vim directory, the proper place to copy it is ~/.vim/syntax/, not ~/.vim/after/syntax/. Vim will then use your syntax file instead of the one in $VIMRUNTIME/syntax.

Your ~/.vim/after/syntax/ directory is the proper place for files that make relatively small tweaks to the syntax highlighting, such as changing the colors of highlight groups. The problem with making major changes in the ~/.vim/after/syntax/ directory is that the behavior of some of Vim's syntax rules depends on the order in which the rules are executed, and any rules in ~/.vim/after/syntax are going to be executed after the rules in $VIMRUNTIME/syntax.

I think the reason that the changes you make to ~/.vim/after/syntax/html.vim are not showing up is because of this line near the bottom of $VIMRUNTIME/syntax/html.vim,

let b:current_syntax = "html"

and this block at the top of $VIMRUNTIME/syntax/html.vim, which is presumably still in your copy in ~/.vim/after/syntax/html.vim:

if !exists("main_syntax")
  if version < 600
    syntax clear
  elseif exists("b:current_syntax")
    finish
  endif
  let main_syntax = 'html'
endif

That block is detecting that b:current_syntax has already been set, so it terminates the script at that point by executing finish. None of your changes to that file are being executed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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