Vim complains about a temporary file when opening syntax highlighted files on Mac OS X

When I try to open a file (e.g. test/test_sequence.rb) using Vim or MacVim I get the following error:

"test/test_sequence.rb" 109L, 3697C
Vim(let):E484: Can't open file /var/folders/zO/zOCN9kiiGD4keWX3TWYEh++++TI/-Tmp-/vzTkbXD/0

This seems only restricted to files which have some kind of syntax highlighting. I can still edit the file but I have to use :w! to write the changes the first time. I'm using vim on Mac OS X. I tried a lot of googling for this error with no luck and this has become really frustrating. Could anyone offer a fix for this?

EDIT: I don't get this error when editing syntax highlighted LaTeX files but do with syntax highlighted Ruby files.


Turns out the problem was with the shell. Vim was trying to use /bin/screen as the shell

set shell /bin/sh

In my vimrc fixed the problem.


I have found that if you su to a different user, processes trying to use temporary files may produce an error like /var/folders/zO/zOCN9kiiGD4keWX3TWYEh++++TI/-Tmp-/vzTkbXD/0: permission denied; the fix for this is to unset TMPDIR (which, I think, causes /tmp to be used instead), because the TMPDIR specified is specific to the old user and not writable by the current user.

You haven't said whether you're using su or any other user-switching, and the error message doesn't mention permission denied, but ...