Skip to content

Instantly share code, notes, and snippets.

@freeo freeo/OpenVim.ahk
Created Sep 22, 2014

What would you like to do?
OpenVim.ahk - Windows Explorer hotkey integration of gVim
; OpenVim.ahk
; Author: Arthur Jaron
; EMail:
; 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
; ### Hotkeys ###
; Win+Enter
; Win+Ctrl+Enter:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.