In bash, is it possible to map backward delete not to physical <Backspace> key but to some other key?

I.e., <F18> has the following escape sequence [1;5Q, and I tried adding the following to my .inputrc:

"\e[1;5Q": backward-delete-char

...but unfortunately with no success. Thus, I wonder, is it possible at all?

  • 2
    It "should" work: if your keyboard really sends that string (which you should verify). Actually, \e[1;5Q doesn't look like a possible <F18> (what terminal type is this?). – Thomas Dickey Feb 20 '16 at 12:58
  • @ThomasDickey, by verify you mean something like cat? Then yes, it does echo that code. Anyway, it's not a physical key, actually. As you surely know, in modern terminals (like iTerm on OS X) you can define your own escape sequences for a key or a keys combination. So, I've done that, and now I'm trying to make it work in bash (as it already works in Vim). But somehow - as described above - with no success, unfortunately. Any suggestions, may be? Thanks! – A S Feb 20 '16 at 18:47
  • Since it works-in-Vim, I assume you got the escape character mapped. But that (literal \e versus escape character) is a detail that might go awry, since your sentence mentioning <F18> has no escape character. – Thomas Dickey Feb 20 '16 at 20:11

In iTerm2 add the following binding (to send hex codes) on <F18> keydown: 0x1b 0x5b 0x31 0x3b 0x35 0x51.

The issue is that your test with cat is misleading. Here's the proper test: cat | xxd. Try before and after adding the hex code rule.

0x1b : escape byte (rendered as ^[)
0x5b : [
0x31 : 1
0x3b : ;
0x35 : 5
0x51 : Q

These are the bytes your inputrc is expecting.

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.