1

It seems that vim does not work correctly when editing files in Windows systems directories. For example, editing the PowerShell all users, all hosts profile script fails. The current file has only one (1) line in it.

C:>Get-Content C:\Windows\System32\WindowsPowerShell\v1.0\profile.ps1
Write-Host "$($PSVersionTable.PSVersion.ToString()) All Users, All Hosts @ $($MyInvocation.MyCommand.Source)"

I use vim to add one line.

1 asdf
2 Write-Host "$($PSVersionTable.PSVersion.ToString()) All Users, All Hosts @ $($MyInvocation.MyCommand.Source)"

After saving and exiting vim, the file remains unchanged.

C:>Get-Content C:\Windows\System32\WindowsPowerShell\v1.0\profile.ps1
Write-Host "$($PSVersionTable.PSVersion.ToString()) All Users, All Hosts @ $($MyInvocation.MyCommand.Source)"

Yet, when I run vim on the file again, it appears with the line I added.

 1 asdf
 2 Write-Host "$($PSVersionTable.PSVersion.ToString()) All Users, All Hosts @ $($MyInvocation.MyCommand.Source)"

I do not see any information about the file being read-only. Using Ctrl-G only presents the expected "profile.ps1" line 1 of 2 --50%-- col 1.

If I start the shell as Administrator and edit the file, it appears to be empty.

1

I am using C:>vim --version VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Nov 6 2016 17:05:36)

2

Are you on 64-bit Windows? If so then I believe you are encountering two different files due to some Windows voodoo. See if you find a mirrored version in this folder:

C:\Windows\SysWOW64\WindowsPowerShell\v1.0

What the heck is that about? It's related to Windows allowing 32-bit programs to be run on a 64-bit system. The 32-bit emulator...

...redirects calls to System32 folder to the SysWOW64 folder transparently so even if the folder is hard coded to the System32 folder (like C:\Windows\System32), the emulator will make sure that the SysWOW64 folder is used instead.

I did some experimenting on my 64-bit system. When I try to edit C:\Windows\System32\WindowsPowerShell\v1.0\profile.ps1 with my 32-bit gvim executable I see the same behavior as you and my changes are actually made to the clone under the SysWOW64 folder. Conversely when I try the same thing using a 64-bit vim executable (from my 64-bit Cygwin install) my changes actually affect the System32 version.

Here's an article that discusses this phenomenon

So what is one to do if one really wants to access a System32 file with a 32-bit editor? Well, there's another magic folder, Sysnative, that makes this possible. Simply replace "System32" with "Sysnative" in the target file's path and you're in business. Note that this magic folder will not be visible to any 64-bit programs and that includes Explorer (the Windows file manager). Crystal clear, no?

Here's an article about Sysnative.

  • Ok. I looks like I have installed a 64-bit vim on Windows. Yes, I also have Cygwin if needed. This seems a mess. I think that vim could do something better. – lit Sep 24 '17 at 22:05
  • Are you sure you don't have 32-bit? Is your installation under /Program Files (x86) or /Program Files (or neither)? I think most people run the 32-bit version as it's recommended (uses less memory for one). If so there's not much Vim could do about this issue. BTW, thanks for accepting my answer and please upvote, too, if you didn't intentionally skip that. Hate to see an extra 10 points go to waste as I try to get to 750. :) – B Layer Sep 25 '17 at 0:26
  • Just to reiterate, a 32-bit program will see the SysWOW64 version while a 64-bit program will see System32 as expected. Yes, that seems backwards but that's how it works (check out the linked article). Then there's this twist: samlogic.net/articles/sysnative-folder-64-bit-windows.htm ... but my advice would be to avoid more black magic lol. – B Layer Sep 25 '17 at 0:42

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.