Problem: Vim does not highlight all my comments apparently because of folds

alt text http://files.getdropbox.com/u/175564/vim-color-problem.png

Note the line 84 where the comment is not highlighted. I move my cursor up and down the same problem continues.

I am not sure whether it is possible to have a complete syntax highlighting with folds. Google-linux did not give any significant result.

Thanks to Nickd! The commands are highlighted correctly when I unfold all folds before the bug in highlighting at the line 84.

How can you highlight all comments when you use folds in Vim?

  • What's your fold method? – nickd Jul 7 '09 at 19:30
  • @nickd: I use the foldmethod marker. – Léo Léopold Hertz 준영 Jul 8 '09 at 14:06
  • 2
    @Masi: Are the comments highlighted correctly when unfolded? – nickd Jul 8 '09 at 21:10
  • @nickd: The commands are highlighted correctly when unfold all folds before the bug in highlighting. – Léo Léopold Hertz 준영 Jul 9 '09 at 15:46

vim sometimes gets confused about formatting, especially if you have a very long file. You can sometimes fix it by pressing ctrl-l, but otherwise, you have to live with the bug.


You could try and see if

:syntax sync fromstart

fixes the issue. This forces vim to work from the start of the file each time it does syntax highlighting. This is slow for large files, but may be acceptable on a per file basis. If it works, you could add an autocommand (or ftplugin) to run the above command for the problematic files.


I use folds on a daily basis, and never had any problem with comments not being highlighted, or any syntax highlighting problems, for that matter.

But, it depends on filetype. I can't recognize it from the screenshot - what filetype is that ?

  • @Idigas: The file is ~/.zshrc, so it does not seem to have a filetype. – Léo Léopold Hertz 준영 Jul 2 '09 at 17:52
  • 1
    @Masi - every file has a filetype. What does it says for ":echo(&ft)" – Rook Jul 2 '09 at 18:09
  • @Idigas: Your command gives me zsh. – Léo Léopold Hertz 준영 Jul 3 '09 at 23:34

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.