Binding keypad numbers for exwm screen shifting
Table of Contents
I now have a perfect use for the rarely-used numpad! Because I have three monitors connected and am an exwm/winum user to navigate all those screens from the keyboard, I have bound that rarely-used numpad to quickly allow for switching between screens, up to 9 (I am not sure my brain could handle more than 9 decisions on viewports, anyway…). The magic is that numpad numbers are a different keycodde than the normal numberline at the top of the keyboard. so you can bind them. They will only take effect when in numlock mode, as otherwise they have yet different keycodes.
The Codes
For the time being, I rebound the keys in two places: within emacs, and withing non-emacs exwm buffers. I may change the latter, since the only place I ever used the traditional usage of the keypad was in browsers for entering credit-card numbers, but for now here it is:
in-Emacs bindings
For me, these are within my personal key-bindings global minor mode:
(defvar tsa-keys-map
(let ((map (make-sparse-keymap)))
;;; the s-# are my old way, where s is the windows super key, but is tricky for the fingers past a window 5
(define-key map (kbd "s-1") 'winum-select-window-1)
(define-key map (kbd "s-2") 'winum-select-window-2)
(define-key map (kbd "s-3") 'winum-select-window-3)
(define-key map (kbd "s-4") 'winum-select-window-4)
(define-key map (kbd "s-5") 'winum-select-window-5)
(define-key map (kbd "s-6") 'winum-select-window-6)
(define-key map (kbd "s-7") 'winum-select-window-7)
(define-key map (kbd "s-8") 'winum-select-window-8)
(define-key map (kbd "s-9") 'winum-select-window-9)
(define-key map (kbd "<kp-1>") 'winum-select-window-1)
(define-key map (kbd "<kp-2>") 'winum-select-window-2)
(define-key map (kbd "<kp-3>") 'winum-select-window-3)
(define-key map (kbd "<kp-4>") 'winum-select-window-4)
(define-key map (kbd "<kp-5>") 'winum-select-window-5)
(define-key map (kbd "<kp-6>") 'winum-select-window-6)
(define-key map (kbd "<kp-7>") 'winum-select-window-7)
(define-key map (kbd "<kp-8>") 'winum-select-window-8)
(define-key map (kbd "<kp-9>") 'winum-select-window-9)
(define-key map (kbd "s-<backspace>") 'kill-current-buffer)
map)
"my-keys-minor-mode keymap.")
exwm-window bindings
I have these located in my use-package section for exwm.
(exwm-input-set-key (kbd "<kp-1>") 'winum-select-window-1)
(exwm-input-set-key (kbd "<kp-2>") 'winum-select-window-2)
(exwm-input-set-key (kbd "<kp-3>") 'winum-select-window-3)
(exwm-input-set-key (kbd "<kp-4>") 'winum-select-window-4)
(exwm-input-set-key (kbd "<kp-5>") 'winum-select-window-5)
(exwm-input-set-key (kbd "<kp-6>") 'winum-select-window-6)
(exwm-input-set-key (kbd "<kp-7>") 'winum-select-window-7)
(exwm-input-set-key (kbd "<kp-8>") 'winum-select-window-8)
(exwm-input-set-key (kbd "<kp-9>") 'winum-select-window-9)
Getting around Windows
I’ve long-since crossed the line where having to use a mouse to manage program focus is almost painfully obnoxious; since 80% of my work is in emacs, I want to use the keyboard whenever possible. With this helper in my numpad, my three ways of window navigation are improved:
- Jump to any character in any visible emacs window with
global-ace-isearch-mode
- Navigate path-wise (for adjacent screens) with
windmove
, easily going up or left to whichever screen - Navigate directly to desired screens with
winum-mode
These three make up the vast majority of my window navigation, and my fingers are happy to have the numpad option now.
Resources
- Ergo emacs with the numpad solution: http://ergoemacs.org/emacs/emacs_bind_number_pad_keys.html
- Ace Isearch: https://github.com/tam17aki/ace-isearch
- Wind Move: https://www.emacswiki.org/emacs/WindMove
- Winum mode: https://github.com/deb0ch/emacs-winum