15

I’m stuck here:

Is it possible to bind one of <enter>, <backspace>, <up>, <down>, <left>, <right> together with control?

\C<foo> shows up as |foo> in the help and ^<up> isn’t bound.
'\C<foo>, '\C <foo>' don’t work, too (same with " instead).

<control> doesn’t exist.

You actually can get ^<foo> to show up in the help, but only if you map ^<foo>, which isn’t exactly what I want. ;)

Profpatsch
  • 1,799

2 Answers2

22

I found the correct answer here: Bind ctrl+up in muttrc | mail-archive.com.

Inside mutt, use the command

:exec what-key

Then pressing the desired key (like Ctrl+arrow) you can learn how to reference any key. In my case I get <C-Up> for Ctrl+Up.

Hit Ctrl-g to exit what-key.

alexis
  • 417
  • 5
    In case you succeeded in using :exec what-key to get this information, but then could not figure out "what-key" to press to get out of the what-key command, the key sequence to exit is Ctrl-g. – KDN Jan 28 '17 at 03:41
  • 1
    In any terminal/config where I tried that (with NeoMutt 20191207 or Mutt 1.13.2) what-key just give me a letter A, B, C or D.

    I am not the only one : https://www.mail-archive.com/mutt-users@mutt.org/msg36985.html

    – Bruno BEAUFILS Jun 03 '20 at 20:54
6

First, you need to determine whether your terminal sends different escape sequences for these key combinations. Applications running in terminals get characters as input, not keys. Function keys are encoded as control characters or as escape sequences beginning with the escape character (which you can write as \e in a key binding).

To see the escape sequence sent by a key combination in a terminal, press Ctrl+V at a shell prompt, then press the key combination. For example, if I press Ctrl+V Ctrl+Left at a shell prompt, I see ^[O5D. ^[ is the escape character, so I would need to bind \eO5D in Mutt to make it react to Ctrl+Left:

bind editor \eO5D backward-word

Some terminals send the same escape sequence for the same key with different modifiers. If that's the case, you'll need to figure out how to change the terminal's behavior or switch to a different terminal.

  • Sounds good, but it doesn’t work. \e is the escape key, not the escape character… – Profpatsch Feb 06 '13 at 12:23
  • @Profpatsch Weird, that binding works for me. I've been using Mutt 1.5 since about forever, maybe 1.4 works differently? Does it work if you use \e in a macro: macro editor \e[O5D \eb? – Gilles 'SO- stop being evil' Feb 06 '13 at 12:47
  • 1
    I’m on Terminator, when I hit Ctrl+Down I get ^[[1;5B, it doesn’t work with bind index \e[1;5B command and not with \e1;5B, too. Oh, I work with Mutt 1.5.21 (Arch. ;) – Profpatsch Feb 06 '13 at 13:48
  • 1
    @Profpatsch Ok, I can reproduce this. There seems to be a limitation to 5 characters: bind editor \e[1\;5 backward-word works for me (and inserts an extra D when I enter ESC [ 1 ; 5 D), but bind editor \e[1\;5D backward-word results in ESC [ 1 ; 5 D doing nothing. I see a limitation to 8 characters in the source code (MAX_SEQ), but nothing that would trigger at 5 characters. – Gilles 'SO- stop being evil' Feb 06 '13 at 15:33
  • @Profpatsch A workaround would be to make your terminal send shorter sequences. I don't know if Terminator supports this. – Gilles 'SO- stop being evil' Feb 06 '13 at 15:35
  • @Gilles, Just for the reference, In Mutt 1.10.1, both bind editor \e[1\;9D backward-word and bind editor \e[1\;9C forward-word do work. – A S Nov 13 '18 at 15:29
  • Any idea what pre-sequence to press on macOS Terminal.app? – Pankaj Jangid Jul 14 '19 at 16:44