Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

alt text

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?

share|improve this question
What's your fold method? – nickd Jul 7 '09 at 19:30
@nickd: I use the foldmethod marker. – Masi Jul 8 '09 at 14:06
@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. – Masi Jul 9 '09 at 15:46
up vote 3 down vote accepted

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.

share|improve this answer

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.

share|improve this answer

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 ?

share|improve this answer
@Idigas: The file is ~/.zshrc, so it does not seem to have a filetype. – Masi Jul 2 '09 at 17:52
@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. – Masi Jul 3 '09 at 23:34

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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