Emacs Keybindings

My workstation keyboard at home doesn't have arrow keys. Someone asked why I'd use a keyboard like this, this is a short blog entry that explains why I don't suffer for not having them.

My keyboard is a Happy Hacking Keyboard. You might know these for their obscene price when new. Don't buy new - buy used. And don't buy domestic, buy international and have the seller mark down the price to get around VAT. It also helps if you buy it, like I did, when your currency is far stronger than it has any business being.

The HHKB doesn't have arrow keys. It has a modifier fn key that can be used to make other keys send arrow keycodes - but you don't want to use them on a UNIX-like system. Instead, you want to introduce yourself to readline(3). Readline is the library your terminal is almost certainly using to provide an interactive editing experience for your prompt. By default, readline(3) provides the user with emacs keybindings - which is ideal for me, because I use emacs.

Using key-combinations to move the cursor is less intuitive. I'm not going to argue otherwise. I do recall when I first started using emacs, I held onto my arrow keys for dear life. But then I started making an effort to touch type, and the constant shifting back and forth between home-row and off-to-the-side got in the way. Years later, and now I use C-b/f/n/p like I was raised on them.

If you want to stick to the home-row by using emacs key binds on your prompt, here's the basics of movement:

Key   Action
----- ----------------------------
C-a   Move to start of line
C-e   Move to end of line
C-f   Move forward one character
M-f   Move forward one word
C-b   Move back one character
M-b   Move back one word

And history:

Key   Action
----- ----------------------------------------------
C-p   Fetch history n-1
C-n   Fetch history n+1
C-r   Fetch history backwards (interactive search)

And finally, cutting and pasting. Which are known as killing and yanking.

Key   Action
----- ----------------------------------------
C-d   Delete character under cursor
M-d   Delete word under cursor
C-k   Delete from cursor to end of line
C-u   Delete from cursor to start of line
C-y   Insert the last item deleted at cursor