Created
September 22, 2014 11:11
-
-
Save freeo/5b1f5ea02e96a68e8263 to your computer and use it in GitHub Desktop.
OpenVim.ahk - Windows Explorer hotkey integration of gVim
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; OpenVim.ahk | |
; | |
; Author: Arthur Jaron | |
; EMail: [email protected] | |
; Overview: | |
; Explorer_GetSelection(): Helper function (found in the AHK-forums) | |
; OpenVim(): Core function | |
; Hotkeys: | |
; Win+Enter: Open current file in gVim session "GVIM" | |
; Win+Ctrl+Enter: Open current selected file in gVim session "ADMIN MODE" with | |
; elevated rights. This wil let you write to protected files, e.g. inside | |
; the Windows/ folder and top-level files (c:\example.txt). | |
Explorer_GetSelection(hwnd="") { | |
; Get the full filepath + name of the currently selected file inside | |
; the explorer window. | |
hwnd := hwnd ? hwnd : WinExist("A") | |
WinGetClass class, ahk_id %hwnd% | |
if (class="CabinetWClass" or class="ExploreWClass" or class="Progman") | |
for window in ComObjCreate("Shell.Application").Windows | |
if (window.hwnd==hwnd) | |
sel := window.Document.SelectedItems | |
for item in sel | |
ToReturn .= item.path "`n" | |
return Trim(ToReturn,"`n") | |
} | |
OpenVim(Admin="") { | |
; Open the currently selected file within explorer in gVim. | |
; Passing a non-empty string as a parameter will bring up the UAC-prompt | |
; to elevate the next gVim session. It doesn't elevate the current existing | |
; "GVIM" session, but opens a new one named "ADMIN MODE". | |
path_name := % Explorer_GetSelection() | |
if (Admin) { | |
Run *RunAs C:\Program Files\Vim\vim74\gvim.exe --servername "ADMIN MODE" --remote-silent "%path_name%",,,OutputVarPID | |
} | |
else { | |
Run, C:\Program Files\Vim\vim74\gvim.exe --servername "GVIM" --remote-silent "%path_name%",,,OutputVarPID | |
} | |
return | |
} | |
; ### Hotkeys ### | |
; Win+Enter | |
#Enter:: | |
OpenVim() | |
return | |
; Win+Ctrl+Enter: | |
^#Enter:: | |
OpenVim("Admin") | |
return |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment