Keith Gaughan

An attempt at public introspection


Fixing a FreeBSD annoyance: shell editing keybindings

· 2min

Unlike all the other systems I use, FreeBSD is lacking in one tiny little area: default shell keybindings. Specifically, there’s no keybindings associated with the arrow keys when CTRL is held down.

I’m used to being able to move back a word with CTRL+LeftArrow is pressed, being able to move forward a word with CTRL+RightArrow, being able to move to the start of the line with CTRL+UpArrow, and being able to move to the start of the line with CTRL+DownArrow, but none of the shells are configured with these bindings by default. There are bindings for the particular functions though, just not these particular ones.

This is a bit of an annoyance, but it’s only recently that I’ve became sufficiently annoyed to fix it. Here’s my zsh bindings, which also work with tcsh:

bindkey '\e[1;5D' backward-word
bindkey '\e[1;5C' forward-word
bindkey '\e[1;5A' beginning-of-line
bindkey '\e[1;5B' end-of-line

Here’s the bash bindings:

bind '"\e[1;5D": backward-word'
bind '"\e[1;5C": forward-word'
bind '"\e[1;5A": beginning-of-line'
bind '"\e[1;5B": end-of-line'

And finally, the FreeBSD sh bindings:

bind "^[[1;5D" ed-prev-word
bind "^[[1;5C" ed-next-word
bind "^[[1;5A" ed-move-to-beg
bind "^[[1;5B" ed-move-to-end

There, fixed.