10

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.

"\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
14

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,
| improve this answer | |
  • thanks for response and link to resources. This solved the problem for me! – the_velour_fog Feb 14 '16 at 1:00
19

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.

| 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 '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 stands with Monica Feb 14 '16 at 1:51
  • 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
  • 4
    @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 'SO- stop being evil' Feb 14 '16 at 21:22
  • 1
    @kba For the record, they're not the only ones. Bash's is actually provided by the GNU Readline library it depends on, which also binds it to <c-q> to match Emacs keybind it's copying. Zsh also binds it to both <c-v> and <c-q> but only if you enable Vim mode, ironically enough. Readline is also used by other things like Python's import rlcompleter enhancement. (Sources: tiswww.case.edu/php/chet/readline/readline.html#SEC9 and man zshzle) – ssokolow Nov 2 '19 at 7:58

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.