views:

1892

answers:

4

Has anyone else found VIM's syntax highlighting of Javascript sub-optimal? I'm finding that sometimes I need to scroll around in order to get the syntax highlighting adjusted, as sometimes it mysteriously drops all highlighting.

Are there any work-arounds or ways to fix this? I'm using vim 7.1.

A: 

Closing the file and reopening it usually helps; But i'm interested in a real solution as well!

D4V360
+9  A: 

You might like to try this improved Javascript syntax highlighter rather than the one that ships with VIMRUNTIME.

Rob Wells
Nice. It even suppports highlighting for jsdoc. Thanks!
asksol
Careful: I notice the author of the improved highlighter changed away from syntax sync fromstart in the most recent version... so the issue you saw may start happening in this highlighter. Looks like in the past, it always did fromstart.
Thomas Kammeyer
I have tried both the 9/12/08 release and the 05/17/07 release, and neither of them improve the situation. Opening a complex javascript file in the middle still results in no highlighting, and I must scroll several pages up to have vim start highlighting correctly.
Michael Gundlach
@thomas and @michael you can set the frame that vim uses for creating the highlighting. i can't remember off the top of my head what the actual setting is but it sets how many lines above, and below, the currently displayed window that vim should look at when determining syntax highlighting
Rob Wells
That one has way too many syntax items linked to Special, but that's easily fixed. And seems to be better than the one shipped with Vim.
graywh
+2  A: 

Syntax coloring synchronization probably needs adjustment. I've found in certain contexts that I need to change it.

Syntax synchronization (":help syn-sync") controls how vim keeps track of refreshes its parse of the code for coloring, so that it can start drawing anywhere in the file.

The defaults don't always work for me, so sometimes I find myself issuing

:syn sync fromstart

I suggest reading through the documentation under

:help syn sync

or just check

:help syntax

and find the section on synchronization.

to make an informed decision among the four available basic options. I maintain mappings to function keys to switch between "fromstart" and "ccomment" modes and for just clearing the sync settings.

Thomas Kammeyer
+2  A: 

For a quick and dirty fix, sometimes I just scroll up and down and the highlighting readjusts. Ctrl-L for a screen redraw can also fix it.

AndrewJFord