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.

1
  • 1
    Of course the root cause of the problem is that GNU Readline does not have a proper ECMA-48 parser (c.f. 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, 2019 at 14:23

2 Answers 2

2

Bind them to redraw-current-line.

6
  • 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.
    – user313992
    Dec 11, 2019 at 17:54
  • There is nop. But unbinding is the correct thing to do, see @paradroid's answer. Apr 12, 2020 at 7:30
  • Where is nop?
    – user313992
    Apr 12, 2020 at 8: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. Apr 14, 2020 at 6: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. Dec 7, 2023 at 4:28
1

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

# Ctrl-Up
"\033[1;5A": ""
# Ctrl-Down
"\033[1;5B": ""
2
  • 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. Apr 12, 2020 at 7: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. Dec 7, 2023 at 2:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .