- Notifications
You must be signed in to change notification settings - Fork7
AutoHotkey script to simulate Emacs keybindings on Windows
License
oneh/autohotkey_emacs_keymap
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
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 andM-b move the cursor 5 times instead of moving through words. WhileM-n andM-p do not exist in Emacs keybindings, they can be a good middle ground whenC-n /C-p are too slow andC-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 atIfWinActive in them_IsGoogleSheets() function. The condition I set is very rough and it returnstrue 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 usingC-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 typeC-q C-p for printing.
*5. Personally I useC-q C-a with Microsoft Paint, whereC-x h andC-x C-p both do not work.
*6. Personally I useC-q C-n with Web browsers.
Launch AutoHotkey (http://ahkscript.org) and loadMyEmacsKeymap.ahk. If you have a fresh installation of AutoHotkey, follow the steps below.
- Create an empty file named
AutoHotkey.ahkin the installation directory and add the following line to the file:
#include%A_ScriptDir%\MyEmacsKeymap.ahk
Copy
MyEmacsKeymap.ahkin the same directoryStart
AutHotkey.exe
Note: If you run AutoHotkey without specifying a script file, the program will first look forAutoHotkey.ahk in the directory where the AutoHotkey executable resides. The path to this directory is stored in theA_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 downC-f, the letterf 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 theahk_class value of such applications to them_IgnoreList list in them_IsEnabled function. Theahk_class value of each application can be identified using Window Spy (AU3_Spy.exe) that comes with AutoHotkey.
The default ignore list includesEmacs,Vim (GVim), andmintty (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 {IfWinActiveahk_class %element%Return0 }
C-M-q works as a toggle switch to suspend and resume the execution of this script. PressingC-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.
About
AutoHotkey script to simulate Emacs keybindings on Windows
Resources
License
Uh oh!
There was an error while loading.Please reload this page.