shell's keyboard mapping

This is about assigning keys right, especially the well known [CTRL]+[left arrow] to move the cursor back one word. Looking for this I spent lots of time reading this outstanding page and others. But none of them kept these information as short as possible and that is what I am going to try here. Notice that this is not shell independent, so that we need to individually setup this. First off to find a keys corresponding keycode (which you need for any config) there are several possibilities:

  • Press [CTRL]+V
  • use the read command

Both of which will return something like ^[[1;5D to you.


  • bash relies on a package called readline, which uses ~/.inputrc as configuration file:

    "e[1;5C": forward-word
  • bind -l lets one look up which commands are available

  • bind -f .inputrc will load your new configuration

csh and tcsh

  • look up an action, which the shell should perform, when you press this key combination with

    bindkey -l

    . I found vi-word-fwd and vi-word-back useful.

  • open your ~/.cshrc and append things you looked up this way with e.g.

    bindkey "^[[1;5C" vi-word-fwd   # CTRL+RIGHT
    bindkey "^[[1;5D" vi-word-back  # CTRL+LEFT
    bindkey "^[[1;3C" vi-word-fwd   # ALT+RIGHT
    bindkey "^[[1;3D" vi-word-back  # ALT+LEFT
    bindkey "^[[3~"   delete-char   # Delete key
  • restart your csh

reset says 'Erase is backspace.'

When you got this and you try to remove chars by hitting backspace, chances are that you won't remove chars, but actually insert something like ?^. That can easily be fixed:

stty erase '^?'

investigation pending

Why the heck do both ^- and ^/ return ^_? Btw: CTRL+_ will undo changes in GNU readline.


The plain old sh under FreeBSD uses libedit instead of readline. Its configuration file is called ~/.editrc and a man page man 5 editrc exists. It also supports a bind command, but with a slightly different syntax compared to csh:

bind ';5C' vi-next-big-word
bind ';5D' vi-prev-big-word
bind ';3C' vi-next-big-word
bind ';3D' vi-prev-big-word
bind '^R'  ed-search-prev-history