6

When you install gvim in Windows, you get a right-click Explorer context menu item: "Edit with Vim". Is there a way of either adding a "Edit with Vim as Administrator", or just changing the existing shortcut to always open the file with Vim in Administrator mode? I tried setting gvim.exe to always run as administrator, but that seems to break the context menu item; it gives the error "Error creating process: Check if gvim is in your path!"

UPDATE: magicandre1981 showed me a nice way of using nircmd to partially achieve what I want. Once I installed nircmd.exe to the windows system32 directory, adding this to the registry (putting it in a .reg file and running it) added a context menu item that let me edit files as admin:

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\*\shell\Edit with Vim as Administrator]

[HKEY_CLASSES_ROOT\*\shell\Edit with Vim as Administrator\command]
@="nircmd.exe elevate \"C:\\Program Files (x86)\\Vim\\vim74\\gvim.exe\" \"%1\""

It's still not quite as nicely integrated as I'd like though, as it doesn't use the Vim helper DLL and requires the use of the additional nircmd tool.

  • You should mark his answer as the correct one. – AzP Feb 24 '15 at 11:27
  • Wait, what? Is the solution now in the question and the answer, which is actually only a hint that doesn't have anything to do with vim, is selected as correct? This is not how StackOverflow works. Please clean this up. – Bruno Bronosky Jul 26 '18 at 20:12
4

I use the tool nircmd which has an option elevate to run programs as admin.

Here is an option to open Visual Studio projects (sln files) as admin:

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\VisualStudio.Launcher.sln\Shell\Open Solution elevated]
"HasLUAShield"=""

[HKEY_CLASSES_ROOT\VisualStudio.Launcher.sln\Shell\Open Solution elevated\Command]
@="\"C:\\Windows\\nircmd.exe\" elevate \"C:\\Program Files (x86)\\Common Files\\Microsoft Shared\\MSEnv\\VSLauncher.exe\" \"%1\""

I have no idea how gvim adds itself to the rightclick, so modify the entries. The HasLUAShield entry adds the UAC shield to the entry to make it easier to see that this run a task as admin.

  • magicandre1981's idea indeed works. Thanks. I have just attached a screenshot here. One thing to add: when you save the .reg file, you had better save it using Encoding of Unicode. Also Check the Vim version and path in the .reg file to see if it is correct for your case. it works! – Bianco Jun 29 '16 at 8:57
  • I don't think this actually contains the answer for vim. I think it is a hint based on Visual Studio. Can we get an actual answer for vim? – Bruno Bronosky Jul 26 '18 at 20:08
  • @BrunoBronosky come on, have a bit of own initiative and look for the key as I don't have vim installed. – magicandre1981 Jul 27 '18 at 14:46
  • In fairness to you I should admit I’m using windows for the first time since about 1997. That said, this might be plenty of info for someone more familiar. But to me, it’s more like an inside joke. I did figure it out. But this was very un-StackOverflow. – Bruno Bronosky Jul 27 '18 at 14:50

protected by magicandre1981 Jun 29 '16 at 15:26

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

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