What I want to do is made C-h not send backwards-delete-char
there is nothing about it in my inputrc files but is shows up in bind -p
C-h
is bound to backward-delete-char
by default. If you don't like that, bind it to a different command in your .inputrc
, e.g.
"\C-h": nop
to make it do nothing.
Note that if your terminal sends C-h for the BackSpace key¹, and C-h
is not explicitly bound to an existing command (so not nop
), then C-h
will execute backward-delete-char
.
¹ More precisely, if your terminal's configuration tell applications that this is so. This is the erase
character in the stty settings. You can display stty settings by running stty -a
.
Binding to the nop
will suppress the key action, but won't help in case you want to free up the key to be a prefix. Suppose you want to dedicate "M-c" as a prefix to a set of related macros, for example, such that the sequence "M-c M-i" is bound to a macro that simply types a long command controlct sensor instance
. Naturally, "M-c M-d" would print something else, and so on.
But there is a default binding "\ec": capitalize-word"
, that would stand in your way. If you print the key sequence "M-c M-i" fast enough (specifically, within the time in milliseconds set by the keyseq-timeout
readline variable), you'll get the desired behavior. But if you linger, bash will execute the "M-c" default binding alone, i. e. the nop
command. So in this case, you really need to unbind the key, not rebind it to something that does nothing.
Fortunately, readline supports that quite easily (@user996142 provided the correct syntax and a reference in a comment):
"\ec":
alone on a line by itself. This clears the binding.
Warning time: Do restart bash (e. g., exec bash -l
), not just reload the .inputrc
file with "C-x C-r". readline may not report the binding after the reload (bind -l
does not show it, and bind -q capitalize-word
happily reports "capitalize-word is not bound to any keys," but still times out it, just as if it were bound to nop
. This is a bug in some versions of either bash or readline.
I had to unbind using the following. The elusive important piece for me was adding the surrounding single quotes.
FWIW, numerous variations work when running the command directly in the shell. But when including the command in .inputrc or a .sh file, this is the only thing that I found to work.
Alt-c
'"\ec":'
Ctrl-c
'"\C-c":'
The following -u <readline command name>
also seems to work sometimes.
bind -u yank
bind '"\C-y":'
bind
command and surrounding single quotes needed in the shell). Using this syntax in inputrc results in readline: `'': missing closing quote for macro
.
Commented
Dec 7, 2023 at 4:40
man readline | grep "C-H"
. Try adding"\C-h": ""
to your~/.inputrc
file.