Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 doesnt work. Ctrl + arrow produces nothing.

"\eC-5C":forward-word
"\eC-5D":backward-word

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

  • terminal: tmux inside gnome-terminal
share|improve this question
up vote 10 down vote accepted

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:

    kDN5=\E[1;5B,
    kLFT5=\E[1;5D,
    kRIT5=\E[1;5C,        
    kUP5=\E[1;5A,
share|improve this answer
    
thanks for response and link to resources. This solved the problem for me! – the_velour_fog Feb 14 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:

^[[1;5C

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

share|improve this answer
    
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 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 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 – BinaryZebra Feb 14 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 at 16:03
2  
@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 at 21:22

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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