I have a strange thing happening on a single file. When I open the file under it's original name, the highlighting is lost (":syntax on" does nothing). But if I cp that file with another name and open it, the syntax highlighting returns. If I mv that copy back to the original file name, the highlighting is gone again.

I can't show you images (as my rep is not high enough), but I assure you if I could, you could clearly see that file a.js has no highlighting while a_copy.js does.

  • 1
    You can upload the screenshot on some image sharing site and add the link.
    – romainl
    Apr 28, 2014 at 19:45
  • 1
    What does :verbose set syntax? (with the question mark as part of the command) show?
    – Heptite
    Apr 29, 2014 at 0:52

4 Answers 4


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

  • syntax= Last set from /usr/local/Cellar/macvim/HEAD/MacVim.app/Contents/Resources/vim/runtime/syntax/syntax.vim filetype= Last set from ~/.vimviews/~=+github=+ctc_services-wrapper=+routes=+ctc_inventory.js=
    – seyDoggy
    Apr 29, 2014 at 11:01
  • So yeah, this file in particular isn't being recognized as a js file.
    – seyDoggy
    Apr 29, 2014 at 11:02
  • 3
    :set syntax=javascript did the trick. Thanks.
    – seyDoggy
    Apr 29, 2014 at 11:04
  • 1
    It was a sudden loss. The syntax was there and then it wasn't. So in all likelihood I had inadvertently hit the right key combo to turn the settings off on that file alone.
    – seyDoggy
    Apr 29, 2014 at 14:49
  • 1
    Thanks, this happened to me too using vim with spf13. No clue why(I did nothing, even reinstalled vim with spf13 and it happened again), the problem anyway was that filetype was lost for some reason. Fully working now!
    – Rawa
    Sep 12, 2014 at 18:43

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 =+.


This is an old question but since this has happened to me several times I thought I might as well share my solution.

As suggested, I compared the original and the copy (with colors) by:

:verbose setlocal syntax? filetype?


        Last set from /usr/share/vim/vim80/syntax/syntax.vim
        Last set from ~/.vim/view/~=+Thesis=+thesis.tex=


        Last set from /usr/share/vim/vim80/syntax/syntax.vim
        Last set from /usr/share/vim/vim80/autoload/dist/ft.vim`

The solution to this for me was to :set filetype=tex (or whatever file extension you're working with.) I haven't been able to track down exactly why this happens but it seems to me that it happens after deleting .swp files.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.