Skip to main content

Vim Fails Syntax Highlighting on a Single File

I had an odd thing happen to me. A python file I was editing lost its syntax highlighting, but only that file. All the other python files still showed syntax correctly. Exiting and re-entering vim changed nothing I tried both of the following commands in vim, however, neither had any impact.

:syntax on
:syntax sync fromstart

To get more information I used the command

:verbose setlocal syntax? filetype?

The filetype showed it was last seen from the vim view directory, which is ~/.vim/view/ on my system. I had been working on my .vimrc file a few days ago and had read about views 1 and how it kept certain information was stored in the ~/.vim/view/ directory. So I tried renaming the file. Ta-da! I had syntax highlighting. Restore the previous filename, and syntax highlighting is missing again. Humm. How about moving the file to another directory? I open it and yes that show correctly.

This had to be a problem with the saved view file in vim, but let us try one last thing; remove the vim view file. I moved it out of the ~/.vim/view directory and tried opening the original file again. Works like a charm.

Now, what is the solution? I don't really want to play with the files in ~/.vim/view even though it will fix the problem. There must be a command I can use to fix this. In my case, I used set syntax=python and that fixed the problem.

Let me know if you have a better solution.


:help mkview in vim