by David Capello
handy (or handy-mode) is a set of keyboard shortcuts that you
could use in any text editor. The idea is to offer a progressive way
to convert your current keyboard shortcuts to a more easy to use set
of shortcuts.
handy offers:
- Simple cursor movements using the
Altmodifier and the home row - A progressive path of change to incorporate new keyshortcuts step by step
- And as a final stage, you will be able to use a modal mode (
vim-like mode) where the same shortcuts are accesible without pressingAltmodifier all the time
It's focused on Emacs, but you could configure other text editors and shells:
Ten years ago (2009~2010) I started experiencing the Emacs pinky problem. Luckily, I've found a great project by Xah Lee: ErgoEmacs. This was the beginning of a journey to re-learn all Emacs keyboard shortcuts, and learning several good UX improvements like grouping several Emacs commands in one keystroke or repetitive keystrokes.
After modifying ErgoEmacs for my own
purposes, I decided to create a
text editor with these shortcuts,
but it was a failed attempt (as it requires too much work/free-time to
finish it). So then the project changed to a more realistic approach:
create a progressive set of shortcuts to switch to handy from any
text editor (Emacs in the first place).
I'll try to include in this document the imagery that is on my own
head when I use handy, that will be helpful for new users to adopt
the new shortcuts.
This is the progressive set of levels that you will learn:
- Level 1 JLIK: Move through characters and lines with
Alt+J/Alt+L/Alt+I/Alt+K - Level 2 NM: Execute commands and cancel execution with
Alt+N/Alt+M - Level 3 UO: Move through words/paragraphs/functions with
Alt+U/Alt+O - Level 4 ZB: Undo/Cut/Copy/Paste and Buffers with
Alt+Z/Alt+X/Alt+C/Alt+V/Alt+B - Level 5 YH: Incremental Search and End/Beginning-of-Line/Buffer Movement with
Alt+Y/Alt+H - Level 6 WERD: Erase stuff with
Alt+W/Alt+E/Alt+R/Alt+D/Alt+F/Alt+G - Level 7 Modal: Switch modes with
Alt+P
In the first level of handy, we have: Alt+J, Alt+L, Alt+I, Alt+K:
.-----.
| I |
.-----'-----'-----.
| J | K | L |
'-----------------'
This set of keys simulate the arrow keys of any keyboard but they are located in the home row mainly (JKL) so you don't have to move your hand to move the cursor:
Alt+J: Moves the cursor one character backward (e.g. Left Arrow,cursorLefton VS Code,backward-charon Emacs)Alt+L: Moves the cursor one character forward (e.g. Right Arrow,cursorRighton VS Code,forward-charon Emacs)Alt+I: Moves the cursor to the previous line (e.g. Up Arrow,cursorUpon VS Code,previous-lineon Emacs)Alt+K: Moves the cursor to the next line (e.g. Down Arrow,cursorDownon VS Code,next-lineon Emacs)
With the Shift modifier, steps get a little wider:
Alt+Shift+J: Moves the cursor one balanced expression backward (e.g.backward-sexpon Emacs)Alt+Shift+L: Moves the cursor one balanced expression forward (e.g.forward-sexpon Emacs)Alt+Shift+I: Moves the cursor one page up (e.g. Page Up,cursorPageUpon VS Code,cua-scroll-downon Emacs)Alt+Shift+K: Moves the cursor one page down (e.g. Page Down,cursorPageDownon VS Code,cua-scroll-upon Emacs)
What is a balanced expression? It can be anything that is balanced
in the actual programming language. For example, on mathematical
expression, it should jump between (...)
x= ( (a+2) * y - (5*z) )
^-----^ ^-----^
^----------------------^
On programming languages it should jump between balanced strings
limits "...", scopes {...}, array indexer [...], etc. When none
of these characters are found, it should move just through words.
.-----.
| |
.-----' '-----.
| |
.-----'-----------------'
| N M |
'-----------'
The second handy level enables the prefix key to open an huge range
of commands, and to cancel actions/commands:
Alt+M, ...: Prefix key for other keys shortcuts (likeCtrl+Kon VS Code, orCtrl+Con Emacs)Alt+Shift+M: Execute command by name (e.g.Ctrl+Shift+Pon VS Code, orexecute-extended-commandon Emacs)Alt+N: Cancels the execution of a command or prefix keys (e.g.Esckey, orCtrl+Gon Emacs)Alt+Shift+N: Creates a new untitled file (e.g. likeCtrl+Ncommand in regular desktop apps)
List of Alt+M, ... commands:
Alt+M, F: Open a file (e.g.Ctrl+Oon VS Code, orfind-fileon Emacs)Alt+M, D: Open a folder/directory (e.g.ido-diredon Emacs)Alt+M, S: Save the file (e.g.Ctrl+Son regular desktop apps, orsave-bufferon Emacs)Alt+M, G: Jump to a specific line number (e.g.Ctrl+Gon VS Code, orgoto-lineon Emacs)
Commands about macros:
Alt+M, M: Start (and then Stop) recording a macro (handy-switch-macro-recordingfunction from handy-mode for Emacs)Alt+M, L: Runs the last recorded macro (e.g.kmacro-end-and-call-macroon Emacs)Alt+M, J: Edit (and then Save) a macro (e.g.handy-switch-macro-editingfunction from handy-mode for Emacs)
Commands about bookmarks:
Alt+M, I:bookmark-jumpAlt+M, K:bookmark-setAlt+M, B:bookmark-bmenu-list
Commands about registers:
Alt+M, Alt+I:jump-to-registerAlt+M, Alt+K:point-to-registerAlt+M, Alt+C:copy-to-registerAlt+M, Alt+V:insert-register
.-----.-----.-----.
| U | | O |
|-----' '-----|
| |
.-----'-----------------'
| |
'-----------'
Alt+U:backward-wordAlt+O:forward-wordAlt+Shift+U:handy-beginning-of-blockAlt+Shift+O:handy-end-of-block
.-----.-----.-----.
| | | |
|-----' '-----|
| |
.-----------------------------.-----'-----------------'
| Z X C V B | |
'-----------. '-----------|
| SPC |
'-----------------------------'
...
.-----.-----.-----.-----.
| Y | | | |
| |-----' '-----|
| H | |
.-----------------------------|-----'-----------------'
| | |
'-----------. '-----------|
| |
'-----------------------------'
...
Alt+Y/Alt+Shift+Y: Forward/backward incremental search (e.g.isearch-forward/isearch-backwardon Emacs)Alt+H/Alt+Shift+H: If you press one time the key it goes to the beginning/end of line (e.g.Alt+Hgoes to the beginning of line), the second time you press it, it goes to the beginning/end of file (e.g.Alt+H, Alt+Hgoes to the beginning of file) (handy-beginning-of-line-and-buffer/handy-end-of-line-and-buffer)
.-----------------. .-----.-----.-----.-----.
| W E R | | | | | |
'-----. '-----| |-----' '-----|
| D F G | | |
.-----------'-----------------|-----'-----------------'
| | |
'-----------. '-----------|
| |
'-----------------------------'
...
-
Alt+W:handy-shrink-whitespace -
Alt+E:backward-kill-word -
Alt+R:kill-word -
Alt+D:delete-backward-char -
Alt+F:delete-char -
Alt+G:kill-char -
Alt+Shift+W:handy-close-file -
Alt+Shift+D:backward-kill-sexp -
Alt+Shift+F:kill-sexp -
Alt+Shift+G:handy-backward-kill-line
In this mode you have just one new keyboard shortcut available: Alt+P
Pressing Alt+P you lock the Alt key prefix for all other levels,
so the first Alt is not necessary to be pressed. Pressing Alt+P
again you disable the lock and you're back to the normal editing mode
(where Alt modifier is required to execute the regular commands in
all other levels).
- The bad thing about this is that you cannot write text when
Altis locked (e.g. pressingLkey meansAlt+Linstead of writting the keyL). - The good side is that you can move easily in the file without
pressing the
Altmodifier all the time.
The idea of Alt+P is that depending on what you need to do you can
lock the Alt key (for navigation) or unlock it (for editing).
How to configure each text editor?
- For bash/readline: .inputrc file
- For zshrc: .zshrc file
- For Emacs: handy-mode
handy is based on ideas from: