tags:

views:

228

answers:

2

It seems to me that Vim's syntax highlighting for Haskell is broken, or very buggy. Multiline comments in Haskell (beginning with {- and ending with -}) are arbitrarily greened-out and un-greened-out. Sometimes dragging the mouse over the commented code causes it to reverse color.

Has anyone else been experiencing this problem?

+1  A: 

This happens with other languages as well, it's just the way vim works. It does not actually use a parser, which would be required to be completely accurate all of the time. Actually, sometimes you may need more than just a syntax parser.

http://vimdoc.sourceforge.net/htmldoc/syntax.html

paul
Are you sure? I've never experienced this problem with other languages, nor with editors without advanced parsing.
xkdkxdxc
It definitely happens in C++, I've had friends mention in before, but can't remember what language it was.
paul
I've also seen it happen in LUA and C#. For example, download the source for the Peggle/Bejeweled World of Warcraft add-ons, and try to edit the .lua files in VIM. They're "optimized" by concatenating every statement into a single line. The LUA interpreter doesn't complain, but syntax hi-lighting seems to give up part way through the line.
Merlyn Morgan-Graham
@Merlyn: If it's all on one line, then that's likely due to the `synmaxcol` option. Vim's syntax highlighting really kills performance when there are really long lines, which is why there's now (as of version 7) an option to limit how much of a single line is highlighted.
jamessan
@jamessan: Thanks for the info! Very useful. Now if you can point me to a code auto-cleanup/formatter for LUA, you'll be my favorite dev for the next 12 hours :)
Merlyn Morgan-Graham
+7  A: 

Vim's syntax highlighting trades off accuracy for performance, by default. To do this, it only examines a certain number of lines before the current position to determine how things should be highlighted. This means that it can sometimes get out of sync.

The different methods it uses to determine how much text to examine can be seen at :help :syn-sync. If you want it to Just Work, use :syn sync fromstart to make Vim consider the entire buffer up to the cursor to determine the highlighting.

jamessan
Keep in mind that when Vi talks about "performance", they are talking about performance on 1980s-era hardware. On a modern machine, it does not take too long to scan the whole file on every keystroke, so you shouldn't worry about enabling that.
jrockway
In general, you're correct, jrockway. However, as I mentioned in my comment on paul's response, Vim has *really* poor performance when dealing with excessively long lines. This can also be compounded by ineffeciently written syntax files (like the ones for html and xml). Typically, one won't experience this when coding but open a decent size xml file that's a single line and you'll see what I mean.
jamessan