Javascript syntax highlighting in vim

Viewed 44668

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.

5 Answers

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 and 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.

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.

Related