Anomaly
Anomaly

Reputation: 1071

Get vim to write files to Program Files in Windows

When I create and open a file with vim, i.e. "vim new.txt" it works fine in a folder like my desktop. However, when I am in "C:\Program Files (x86)\Vim\vimfiles\ftplugin\" and I try to create a file with "vim python.vim" or "vim new.txt", vim opens and appears to work fine, but after I save the file and exit vim, it does not exist in the folder. HOWEVER, if I type "vim python.vim" again to re-open the (apparently non-existent) file, vim comes up happily right where I left off in the file that doesn't exist. Can someone tell me what is going on and how to fix it?

Edit: A search of my filesystem for the nonexistent files shows them to in "C:\Users\Daniel\AppData\Local\VirtualStore\Program Files (x86)\Vim\vimfiles\ftplugin" instead of the "C:\Program Files (x86)\Vim\vimfiles\ftplugin\" from which they were created. Any ideas why, though, and how to make this not happen?

Upvotes: 0

Views: 962

Answers (1)

Ingo Karkat
Ingo Karkat

Reputation: 172600

What you're experiencing is the file system redirection of the %ProgramFiles% location (the same is done for the Windows system files under %WINDIR%), because you're not running under an elevated account. Starting with Windows Vista, when User Account Control (UAC) is enabled, you cannot directly access system files and installed applications any more (for security reasons). Windows detects software installers and prompts you to elevate the account, but it doesn't detect Vim's accesses, and (for backward compatibility) redirects those accesses to the VirtualStore.

There are several ways around this:

  • Turn off UAC (bad idea, lower security)
  • Start an elevated instance of GVIM (search for gvim in the Start Menu, and select with Ctrl + Shift + Enter), and edit with that.
  • Avoid the problem by creating a vimfiles directory at %HOME% (C:\Users\Daniel for you) instead of $VIM/vimfiles and put your config there (see :help vimrc).

Upvotes: 2

Related Questions