How to make ctrl-arrow keys move forward/backward a word at a time in Cygwin bash


In the default Cygwin installation, using CTRL-LEFTARROW or CTRL-RIGHTARROW simply prints 5C or 5D instead of skipping a word at a time as expected.

Home/End keys work properly, so remapping should be possible.

Best Answer

Found a solution, posting it here for posterity.

Add the following lines to ~/.inputrc (C:\cygwin\home\<username>\.inputrc):

"\e[1;5C": forward-word   # ctrl + right
"\e[1;5D": backward-word  # ctrl + left 

When done you can press C-x C-r to re-read the .inputrc file for the current session.

Things to note if you want other similar customisations: Use 5A and 5B for up and down arrows, and 2x for shifted versions.

The "official" key mappings are described in the Bash Reference Manual, but for a quick way to find a key mapping, in bash:

  1. type Ctrl+V
  2. type the key sequence you are interested in (e.g., Alt+). This would print ^[[1;3C
  3. remove the leading ^[ and replace it with \e to make \e[1;3C
  4. place this value in your .inputrc file.