Skip to content

Instantly share code, notes, and snippets.

@jongbinjung
Created December 14, 2012 17:48
Show Gist options
  • Save jongbinjung/4287262 to your computer and use it in GitHub Desktop.
Save jongbinjung/4287262 to your computer and use it in GitHub Desktop.
Vi-like navigation for AutoHotKey
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
; HotKey to Initiate VI-mode with Double-tap of Alt
Shift::
If (A_PriorHotKey = "Shift" AND A_TimeSincePriorHotKey < 200)
{
; Set the flags for OSD
Gui, 99:+AlwaysOnTop -Caption +ToolWindow +Disabled -SysMenu +Owner
; Add and set the OSD Text
Gui, 99:Font, s12 bold
Gui, 99:Add, Text, cAA0000, VIM-Mode Activated (Esc to Exit Vim-Mode)
; OSD Background Color (Black)
Gui, 99:Color, 000000
Gui, 99:Show,NoActivate xCenter y10, VIM-Mode Activated
}
Send, {ShiftUp}
Return
#IfWinExist VIM-Mode Activated
; ESC ends VIM-mode
ESC:: Gui, 99:Destroy
; cursor movements
h:: SendInput {Left Down}
j:: SendInput {Down Down}
k:: SendInput {Up Down}
l:: SendInput {Right Down}
; page movements
w:: SendInput ^{Right}
b:: SendInput ^{Left}
x:: SendInput {Delete}
0:: SendInput {Home}
-:: SendInput {End}
$:: SendInput {End}
; selection movements with Shift
+h:: SendInput +{Left Down}
+j:: SendInput +{Down Down}
+k:: SendInput +{Up Down}
+l:: SendInput +{Right Down}
+w:: SendInput +^{Right}
+b:: SendInput +^{Left}
+x:: SendInput +{Delete}
):: SendInput +{Home}
_:: SendInput +{End}
; Copy (Yank) / Cut (Delete) / Paste (Put)
y:: ^c
p:: ^v
d:: ^x
; HotKey to VIM maps
u:: SendInput ^z
#IfWinExist
; cursor movements
; !h:: SendInput {Left Down}
; !j:: SendInput {Down Down}
; !k:: SendInput {Up Down}
; !l:: SendInput {Right Down}
; page movements
; !w:: SendInput ^{Right}
; !b:: SendInput ^{Left}
; !x:: SendInput {Delete}
; !0:: SendInput {Home}
; !-:: SendInput {End}
; selection movements with Shift
; +!h:: SendInput +{Left Down}
; +!j:: SendInput +{Down Down}
; +!k:: SendInput +{Up Down}
; +!l:: SendInput +{Right Down}
; +!w:: SendInput +^{Right}
; +!b:: SendInput +^{Left}
; +!x:: SendInput +{Delete}
; !):: SendInput +{Home}
; !_:: SendInput +{End}
; HotKey to VIM maps
; !u:: SendInput ^z
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment