4

I've run into a weird problem with Vim on Win8 that I just can't get my head around. Some of the stuff I'm going to mention happened months ago and therefore aren't fresh in my memory anymore, so please forgive me if I accidentally leave things out or can't be definitive on some details.

So several months ago, while looking into combining Vim and LaTeX, I discovered LaTeX-Suite (or Vim-LaTeX). When installing this plug-in, one is instructed to set a few things in one's _vimrc file. I did this and added just a few settings of my own. I was going to add more as I went along but I got distracted from Vim and now here we are.

Anyway. I'm pretty sure I did all this in the commandline, which I think is relevant to my problem, because I've now discovered that the contents of my _vimrc file depend on the manner in which I open it. In particular, those lines I added a couple months ago, are missing from the file if I open it with gVim (regardless of whether I use the context menu or launch gVim from the commandline). Same song for any other graphical text editor. Only if I open it with Vim from the commandline, the lines are there.

What is going on here? Are these lines somehow trapped in Vim limbo? Do I need to call the Ghostbusters? How can the same file have different contents depending on the text editor?


I FOUND A CLUE!

In trying to determine which file was being copied depending on whether I did so from the commandline or from the context menu in Windows Explorer, I found out a crucial detail.

In order to copy files in the Program Files (x86) folder, one needs to run cmd.exe as admin. I discovered that my extra lines in the _vimrc file were absent if I opened it with Vim in an admin commandline. So copying as admin copies the file with the limited contents, copying it without admin rights (to the Documents folder for example) will copy the file with the extra lines. Still weird (because I don't have admin rights when I simply open the file with gVim from the context menu) but at least this sheds some light on the underlying cause. Is anyone able to connect the dots for me?

7
  • 1
    I'm guessing your "home" directory is different between the two (gvim vs CLI Vim). Try executing the following in each and see how it compares: :echo $MYVIMRC
    – John O'M.
    Commented May 8, 2015 at 17:00
  • 1
    That was one of my first suspicions as well, so I'm afraid I've tried that already with identical results for both. :(
    – Wouter
    Commented May 8, 2015 at 17:05
  • 1
    And when editing the vimrc, does :echo expand('%:p') show the same thing in each as well?
    – John O'M.
    Commented May 8, 2015 at 17:14
  • It does indeed.
    – Wouter
    Commented May 8, 2015 at 17:27
  • Wow. Then I'm inclined to say that vim truly thinks it is editing the same file, which is backed up by your extra info about copying the file. Might be a feature in Windows. The folks at Super User might be able to shed more light on this. Let us know if you're interested in migrating this.
    – John O'M.
    Commented May 8, 2015 at 18:03

1 Answer 1

8

You're seeing the effects of the Windows File System Redirector. When you edit files in %ProgramFiles% without administrative rights / user account elevation (which isn't allowed in modern version of Windows), Windows redirects the file access to another location inside your user's home directory (to support legacy applications that were written to persist runtime data into their installation location inside %ProgramFiles%).

Therefore, Vim instances run with / without user elevation see different .vimrc configurations. (Something similar can happen if you use both 32- and 64-bit versions concurrently.)

In general, do not modify any Vim runtime files at the installation location! Instead, put your .vimrc (and any plugins you install) inside your user's home directory (Usually C:\Users\<username>); cp. :help .vimrc.

2
  • I'm still not sure I understand what's going on. Can you elaborate on precisely how this causes opening a file from the context menu, not explicitly as admin (though on the admin account), to be the same as opening it from the command line as admin? Also, if file access is being redirected, I assume I should have another _vimrc file somewhere else, with the other contents. Searching for _vimrc I found one at C:\Users\<username>\AppData\Local\VirtualStore\Program Files (x86)\Vim, so that's probably it, right?
    – Wouter
    Commented May 9, 2015 at 10:37
  • 1
    Yes, VirtualStore, that's what it's called. I'm not sure about the detailed circumstances; sometimes (opening certain locations), Windows detects that elevation is necessary and does that automatically. I can just say for sure that without elevation, you get redirected. Commented May 9, 2015 at 18:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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