MyEmacsKeymap.ahk
is an AutoHotkey script to simulate Emacs keybindings on Windows.
This script is made largely based on the scripts provided in the following web sites.
- WindowsでEmacs風キーバインド
- Windows の操作を emacs のキーバインドで行うための設定(AutoHotKey版)
Buffers and Files | Select, Delete, Copy & Paste | ||
---|---|---|---|
C-x C-f | find-file | C-SPC | set-mark-command |
C-x C-s | save-buffer | C-x h | mark-whole-buffer |
C-x C-w | write-file | C-x C-p | mark-page |
C-x k | kill-buffer | C-d | delete-char |
C-x C-c | kill-emacs | C-b | delete-backward-char |
Cursor Motion | C-k | kill-line | |
C-f | forward-char | C-w | kill-region |
C-b | backward-char | M-w | kill-ring-save |
C-n | next-line | C-y | yank |
C-p | previous-line | Search | |
M-f | forward-char x 5 [*1] | C-s | isearch-forward [*2] |
M-b | backward-char x 5 [*1] | C-r | isearch-forward [*2] |
M-n | next-line x 5 [*1] | Undo, Cancel | |
M-p | previous-line x 5 [*1] | C-/ | undo |
C-a | move-beginning-of-line | C-x u | undo |
C-e | move-end-of-line | C-g | keyboard-quit |
C-v | scroll-down | Others | |
M-v | scroll-up | C-m | new-line |
M-< | beginning-of-buffer | C-i | indent-for-tab-command |
M-> | end-of-buffer | C-j | new-line |
Input Method Switching | C-o | open-line | |
C-x C-j | toggle-input-method | C-t | transpose-chars |
C-\ | toggle-input-method | ||
Microsoft Excel, Google Sheets [*3] | |||
C-c a | Activates the selected cell with the cursor at the end (Append) (F2 ) |
||
C-c i | Activates the selected cell with the cursor at the beginning (Insert) (F2 + Home ) |
||
C-q prefix: Temporarily disabling Emacs keybindings[*4] | |||
C-q C-a | (Select All) [*5] | C-q C-n | (New Window) [*6] |
C-q C-p | (Print) | ||
C-M keys: Special keys for administration | |||
C-M-q | Suspends or resumes the execution of this script | ||
C-M-z | Tells whether the implemented keybindings should be enabled or not for the application you are on |
*1. M-f
and M-b
move the cursor 5 times instead of moving through words. While M-n
and M-p
do not exist in Emacs keybindings, they can be a good middle ground when C-n
/ C-p
are too slow and C-v
/ M-v
are too fast for page scrolling.
*2. Search is not incremental. Backward search is not implemented, either.
*3. Whether the active application is Google Sheets is determined at IfWinActive
in the m_IsGoogleSheets()
function. The condition I set is very rough and it returns true
whenever I am using FireFox or Google Chrome. You may want to modify the code to set a more suitable condition.
*4. The idea of using C-q
to temporarily turn off the tool is from XKeymacs, another keybinding tool I used to use. I have used XKeymacs for so long that it has become almost a reflex to type C-q C-p
for printing.
*5. Personally I use C-q C-a
with Microsoft Paint, where C-x h
and C-x C-p
both do not work.
*6. Personally I use C-q C-n
with Web browsers.
Launch AutoHotkey (http://ahkscript.org) and load MyEmacsKeymap.ahk
. If you have a fresh installation of AutoHotkey, follow the steps below.
- Create an empty file named
AutoHotkey.ahk
in the installation directory and add the following line to the file:
#include %A_ScriptDir%\MyEmacsKeymap.ahk
-
Copy
MyEmacsKeymap.ahk
in the same directory -
Start
AutHotkey.exe
Note: If you run AutoHotkey without specifying a script file, the program will first look for AutoHotkey.ahk
in the directory where the AutoHotkey executable resides. The path to this directory is stored in the A_ScriptDir
built-in variable, and can be referenced as %A_ScriptDir%
.
Refer to the following link for a tutorial on how to use AutoHotkey:
- AutoHotkey Biginner Tutorial
"Key slips" may occur when holding down keys. For example, when holding down C-f
, the letter f
may slip and appear on its own in the output, or the original Windows keymap gets incorrectly passed and the search box may pop up. These symptoms can be suppressed by lowering the Repeat Rate of the keyboard in Control Panel.
Add the ahk_class
value of such applications to the m_IgnoreList
list in the m_IsEnabled
function. The ahk_class
value of each application can be identified using Window Spy (AU3_Spy.exe
) that comes with AutoHotkey.
The default ignore list includes Emacs
, Vim
(GVim), and mintty
(Cygwin Terminal).
m_IsEnabled() {
global
;; List of applications to be ignored by this script
;; (Add applications as needed)
;; Emacs - NTEmacs
;; Vim - GVim
;; mintty - Cygwin
m_IgnoreList := ["Emacs", "Vim", "mintty"]
for index, element in m_IgnoreList
{
IfWinActive ahk_class %element%
Return 0
}
C-M-q
works as a toggle switch to suspend and resume the execution of this script. Pressing C-M-q
is the same as selecting "Suspend Hotkeys" from the right-click menu in the AutoHotkey task bar icon.
It is a limitation of this script. The porpuse of this script is just to make Windows a little more comfortable to use, not to perfectly emulate Emacs functionality. Also feel free to modify this script as fits your needs.