Skip to content

andrewroldugin/autohotkey_emacs_keymap

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

51 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Emacs Keybindings on Windows with AutoHotkey

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.

Implemented Keybindings

Buffers and FilesSelect, Delete, Copy & Paste
C-x C-ffind-fileC-SPCset-mark-command
C-x C-ssave-bufferC-x hmark-whole-buffer
C-x C-wwrite-fileC-x C-pmark-page
C-x kkill-bufferC-ddelete-char
C-x C-ckill-emacsC-bdelete-backward-char
Cursor MotionC-kkill-line
C-fforward-charC-wkill-region
C-bbackward-charM-wkill-ring-save
C-nnext-lineC-yyank
C-pprevious-lineSearch
M-fforward-char x 5 [*1]C-sisearch-forward [*2]
M-bbackward-char x 5 [*1]C-risearch-forward [*2]
M-nnext-line x 5 [*1]Undo, Cancel
M-pprevious-line x 5 [*1]C-/undo
C-amove-beginning-of-lineC-x uundo
C-emove-end-of-lineC-gkeyboard-quit
C-vscroll-downOthers
M-vscroll-upC-mnew-line
M-<beginning-of-bufferC-iindent-for-tab-command
M->end-of-bufferC-jnew-line
Input Method SwitchingC-oopen-line
C-x C-jtoggle-input-methodC-ttranspose-chars
C-\toggle-input-method
Microsoft Excel, Google Sheets [*3]
C-c aActivates the selected cell with the cursor at the end (Append) (F2)
C-c iActivates 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-qSuspends or resumes the execution of this script
C-M-zTells 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.

Usage

Launch AutoHotkey (http://ahkscript.org) and load MyEmacsKeymap.ahk. If you have a fresh installation of AutoHotkey, follow the steps below.

  1. Create an empty file named AutoHotkey.ahk in the installation directory and add the following line to the file:
#include %A_ScriptDir%\MyEmacsKeymap.ahk
  1. Copy MyEmacsKeymap.ahk in the same directory

  2. 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:

Notes

How to prevent "key slips" when holding down keys

"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.

How to prevent certain applications from getting affected by this script

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
  }

How to suspend and resume the execution of this script

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.

Sometimes it may not work as expected...

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

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • AutoHotkey 99.9%
  • Batchfile 0.1%