3

You can bind keys like Ctrl-Left and Ctrl-Right in .inputrc like this:

# Ctrl-Left
"\033[1;5D": backward-word
# Ctrl-Right
"\033[1;5C": forward-word

How would I bind Ctrl-Up and Ctrl-Down to nothing?

# Ctrl-Up
"\033[1;5A": null
# Ctrl-Down
"\033[1;5B": null

This obviously does not work.

I use these keys for doing stuff in tmux (nested configuration), but often ;3~ gets output into the terminal when I use either of the keys.

I'm hoping that I will be able to bind them to nothing while still having the keys work for tmux.

paradroid
  • 1,203
  • 1
    Of course the root cause of the problem is that GNU Readline does not have a proper ECMA-48 parser (c.f. https://unix.stackexchange.com/a/523308/5132 and its further reading). But how to do a no-op in Readline is a valid question in its own right. – JdeBP Dec 11 '19 at 14:23

2 Answers2

2

Bind them to redraw-current-line.

  • of course, in bash you can use bind -x with an empty script (bind -x '"\033[1;5D":'), but I assume that the Q is about readline in general. –  Dec 11 '19 at 17:54
  • There is nop. But unbinding is the correct thing to do, see @paradroid's answer. – kkm -still wary of SE promises Apr 12 '20 at 07:30
  • Where is nop? –  Apr 12 '20 at 08:35
  • 1
    I always thought it was a thing, but it appears that binding to any undefined function name has the same effect. "\e=": is bound to possible-completions by default. Putting any of the lines "\e=":,"\e=": nop, "\e=": foobar results in bind -p | fgrep '"\e=' printing nothing (And M-= does not do anything). It appears either RL or bash is permissive: no diagnostics, no nothing. Sorry I was misleading you. In fact, "\e=": w/o arguments unbinds the key just fine. – kkm -still wary of SE promises Apr 14 '20 at 06:44
  • @kkm-stillwaryofSEpromises It seems this works for simple key sequences involving 1 Ctrl or escape. For sequences with both, running e.g. bind '"\e\C-f":' on the command line reliably unbinds the sequence from shell-forward-word, but does not work in inputrc. It seems like a bug. – SpinUp __ A Davis Dec 07 '23 at 04:28
  • @SpinUp__ADavis Thanks, interesting. I'll try to figure out. – kkm -still wary of SE promises Dec 09 '23 at 06:25
1

I found that another option is to use double quotation marks.

# Ctrl-Up
"\033[1;5A": ""
# Ctrl-Down
"\033[1;5B": ""
paradroid
  • 1,203
  • This is the correct answer. This difference is important when the bound key is also prefix to a multi-key sequence: if the head key is not bound, readline waits for the second key indefinitely; if it's bound, only for a short timeout. – kkm -still wary of SE promises Apr 12 '20 at 07:33
  • This is not quite the same as unbinding the key -- this actually binds it to an empty macro, which may or may not work for a particular application. You can see the macros using bind -s. – SpinUp __ A Davis Dec 07 '23 at 02:46