SaltyCrane Blog — Notes on JavaScript and web development

On the quest for consistent keybindings

I'm trying to get consistent keybindings in the applications which I use the most starting with Emacs, then bash/screen, conkeror (my web browser), and others like KPDF and OpenOffice. I haven't got complete consistency, but I'm making progress. Here are my notes on setting the keybindings for a few of the applications. Maybe when I find the perfect setup, I will write about my complete configuration. Until then, here are some sparse notes. Note, for some reason, I've mixed in vi-style, h-j-k-l, movement keybindings with the standard emacs keybindings. I use control+h,j,k,l to move around by character or line and meta+h,j,k,l to move by word or page. I've been using this for several months and it works pretty well-- much better than using pgup/pgdown and the arrow keys.



Emacs

Here is part of my ~/.emacs:

;; buffer switching
(iswitchb-mode t)
(global-set-key "\C-b" 'switch-to-buffer)

;; movement key bindings (use h-j-k-l for movement like vi)
(global-set-key "\C-l" 'forward-char)
(global-set-key "\C-h" 'backward-char)
(global-set-key "\C-j" 'next-line)
(global-set-key "\C-k" 'previous-line)
(global-set-key "\M-l" 'forward-word)
(global-set-key "\M-h" 'backward-word)
(global-set-key "\M-j" 'scroll-up)
(global-set-key "\M-k" 'scroll-down)

;; rebind displaced movement key bindings
(global-set-key "\C-p" 'kill-line)
(global-set-key "\M-v" 'downcase-word)
(global-set-key "\M-b" 'recenter)


Readline (bash)

To change the keybindings for readline (bash), I edited my ~/.inputrc. Luckily, readline is very similar to Emacs and there are a lot of commands that I didn't know about. Here are a few examples. For a full list of commands see the readline manpage.

# ~/.inputrc
"\C-h": backward-char
"\C-l": forward-char
"\M-h": backward-word
"\M-l": forward-word


GNU Screen

Here are some keybindings I use in GNU Screen. I use C-b to switch windows like Emacs buffers. I enter copy mode by pressing M-k and exit by pressing C-g. The "-m" means the keybinding is for copy mode only. "stuff" is used to stuff some stuff into the input buffer. "^" is used for Ctrl and "^[" is used for Meta (Alt).

# ~/.screenrc
bindkey "^B" select         # like emacs switch buffers
bindkey "^[k" eval "copy" "stuff ^b"
bindkey "^k" eval "copy" "stuff k"
bindkey -m "^[j" stuff ^f   # move down one page
bindkey -m "^[k" stuff ^b   # move up one page
bindkey -m "^[h" stuff b    # move backward word
bindkey -m "^[l" stuff w    # move forward by word
bindkey -m "^j" stuff j     # move down one line
bindkey -m "^k" stuff k     # move up one line
bindkey -m "^h" stuff h     # move back one character
bindkey -m "^l" stuff l     # move forward one character
bindkey -m "^e" stuff $     # move to end of line
bindkey -m "^a" stuff 0     # move to beginning of line
bindkey -m "^f" stuff ^s    # incremental search forward
bindkey -m "^ " stuff " "   # set mark
bindkey -m "^g" stuff q     # exit copy mode


Conkeror

My ~/.conkerorrc keybindings section is pretty long, so I won't include it. But again, I use C-b to switch buffers, and Ctrl and Meta plus h-j-k-l to navigate.



OpenOffice.org

This is directly from Appendix A Keyboard Shortcuts in the Getting Started Guide. Unfortunately, OpenOffice doesn't allow me to use the Meta (Alt) key for custom keybindings so I can't use my usual Emacs keybindings. Apparently, Peter in this forum thread had the same lament. If anyone knows how to fix this, please let me know.

To adapt shortcut keys to your needs, use the Customize dialog, as described below.
    1) Select Tools > Customize > Keyboard. The Customize dialog (Figure 1) opens.
    2) To have the shortcut key assignment available in all components of OpenOffice.org select the
       OpenOffice.org button.
    3) Next select the required function from the Category and Function lists.
    4) Now select the desired shortcut keys in the Shortcut keys list and click the Modify button at
       the upper right.
    5) Click OK to accept the change. Now the chosen shortcut keys will execute the function
       chosen in step 3 above whenever they are pressed.


KPDF

I like KPDF better than Evince. I haven't tried anything else. To change some keyboard shortcuts in KPDF go to "Settings", "Configure Shortcuts..."

Comments