Vim syntax highlighting lost on single file

You provide very little information about your environment and configuration, so I can just help you help yourself.

Compare the following options for the two different JavaScript files:

:verbose setlocal syntax? filetype?

Then check the list of :autocmd for any pattern that might target the problematic JavaScript file. Do you use a local vimrc plugin? It might affect this, too.

If all that doesn't provide a clue, capture the sequence of commands with

:set verbose=20 | edit a.js

and watch out for commands that affect 'syntax'.


Try deleting any saved views (i.e. from mkview). I often have this problem if I didn't cleanly exit all my vims when I logout/shutdown. If you've set something like

au BufWinLeave ?* mkview

in your .vimrc as many do, you'll automatically have these views. As mentioned in the accepted answer, you can find where this file is by using:

:verbose setlocal syntax? filetype?


Apart from having syntax on in .vimrc, you may also need to delete a view that has been stored for this particular file in the .vim/view dir:

$ cd ~/.vim/view

# list all files looking for your particular file
$ ls -lt # | head -10 
...

# delete that file
$ rm ...

Note that files in the view/ folder will have their full path on the filesystem, with the / replaced by =+.