I am trying to configure my bash ~/.inputrc to these settings
(Note: , mean the left and right arrow keys)

  • Ctrl + - should jump back a word
  • Ctrl + - should jump forward a word

Currently I have this in my ~/.inputrc and it doesn't work. Ctrl + arrow produces nothing.


I'm sure my escape sequence is wrong.
What are the correct escape sequences for the Ctrl + arrow combinations?

  • terminal: tmux inside gnome-terminal

Gnome-terminal (more properly VTE) imitates some version of xterm's escape sequences. How closely it does this, depends on the version of VTE.

The relevant xterm documentation is in the PC-Style Function Keys section of XTerm Control Sequences.

What you are looking for is a string like \e[1;5D (for control left-arrow), where the 5 denotes the control modifier.

In ncurses, you can see these strings using infocmp -x, as the values for kUP5, kDN5, kLFT5 and kRIT5. For example:

  • thanks for response and link to resources. This solved the problem for me! – the_velour_fog Feb 14 '16 at 1:00

The simplest way to find what are the codes of a key sequence is to use ctrl - v.

So, you type ctrl V and ctrl to get:


Which is a way to write ESC[1;5C or \e[1;5C.

  • wow, cool. do you know if that an intended feature of gnome-terminal, or is it something that was discovered by accident? – the_velour_fog Feb 14 '16 at 1:35
  • Both zsh (bindkey|grep 'quoted-insert') and bash (bind -p|grep 'quoted-insert') have a key binding to output the key codes set to <c-v>. – kba Feb 14 '16 at 1:51
  • @the_velour_fog No, no accident. Those are codes used by xterm. The actual definition of all the codes is quite long. Your head will spin if you try to understand it all. :-) ...... Wikipedia also has a good page about ANSI codes: en.wikipedia.org/wiki/ANSI_escape_code – user79743 Feb 14 '16 at 2:00
  • 1
    For what it's worth, Ctrl-V performs the same function in Vim's Insert and Command modes. – joeytwiddle Feb 14 '16 at 16:03
  • 3
    @the_velour_fog Ctrl+V meaning “insert the next character instead of interpreting it as a terminal command” dates back from the early days of Unix. It's a feature of the kernel's command line processing that's been imitated by more sophisticated input systems such as bash, zsh, vi, ... – Gilles Feb 14 '16 at 21:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.