Skip to content

Instantly share code, notes, and snippets.

@1yx
Created August 8, 2018 05:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 1yx/30c27f7c16fe7311634237b6182490ab to your computer and use it in GitHub Desktop.
Save 1yx/30c27f7c16fe7311634237b6182490ab to your computer and use it in GitHub Desktop.
An AutoHotKey script that provides UNIX & Linux keyboard shortcuts on Windows
;;
;; fork from https://github.com/usi3/emacs.ahk/blob/master/emacs.ahk
;;
;; An autohotkey script that provides emacs-like keybinding on Windows
;;
#InstallKeybdHook
#UseHook
; The following line is a contribution of NTEmacs wiki http://www49.atwiki.jp/ntemacs/pages/20.html
SetKeyDelay 0
; turns to be 1 when ctrl-x is pressed
;is_pre_x = 0
; turns to be 1 when ctrl-space is pressed
;is_pre_spc = 0
; Applications you want to disable emacs-like keybindings
; (Please comment out applications you don't use)
is_target()
{
IfWinActive,ahk_class mintty
Return 1
IfWinActive,ahk_class Emacs
Return 1
IfWinActive,ahk_class ConsoleWindowClass ; Cygwin
Return 1
IfWinActive,ahk_class MEADOW ; Meadow
Return 1
IfWinActive,ahk_class cygwin/x X rl-xterm-XTerm-0
Return 1
; IfWinActive,ahk_class MozillaUIWindowClass ; keysnail on Firefox
; Return 1
; Avoid VMwareUnity with AutoHotkey
IfWinActive,ahk_class VMwareUnityHostWndClass
Return 1
IfWinActive,ahk_class Vim ; GVIM
Return 1
; IfWinActive,ahk_class SWT_Window0 ; Eclipse
; Return 1
; IfWinActive,ahk_class Xming X
; Return 1
; IfWinActive,ahk_class SunAwtFrame
; Return 1
Return 0
}
delete_char()
{
Send {Del}
Return
}
delete_backward_char()
{
Send {BS}
Return
}
kill_line()
{
Send {ShiftDown}{END}{SHIFTUP}
Sleep 50 ;[ms] this value depends on your environment
Send ^x
Return
}
open_line()
{
Send {END}{Enter}{Up}
Return
}
undo()
{
Send ^z
global is_pre_spc = 0
Return
}
move_beginning_of_line()
{
global
Send {HOME}
Return
}
move_end_of_line()
{
global
Send {END}
Return
}
previous_line()
{
global
Send {Up}
Return
}
next_line()
{
global
Send {Down}
Return
}
forward_char()
{
global
Send {Right}
Return
}
backward_char()
{
global
Send {Left}
Return
}
^f::
If is_target()
Send %A_ThisHotkey%
Else
forward_char()
Return
^d::
If is_target()
Send %A_ThisHotkey%
Else
delete_char()
Return
^h::
If is_target()
Send %A_ThisHotkey%
Else
delete_backward_char()
Return
^k::
If is_target()
Send %A_ThisHotkey%
Else
kill_line()
Return
^/::
If is_target()
Send %A_ThisHotkey%
Else
undo()
Return
^a::
If is_target()
Send %A_ThisHotkey%
Else
move_beginning_of_line()
Return
^e::
If is_target()
Send %A_ThisHotkey%
Else
move_end_of_line()
Return
^p::
If is_target()
Send %A_ThisHotkey%
Else
previous_line()
Return
^n::
If is_target()
Send %A_ThisHotkey%
Else
next_line()
Return
^b::
If is_target()
Send %A_ThisHotkey%
Else
backward_char()
Return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment