5

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

  • It is default for both vi and emacs mode, check man readline | grep "C-H" . Try adding "\C-h": "" to your ~/.inputrc file. – user996142 Jun 30 '17 at 16:00
4

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.

| improve this answer | |
3

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.

| improve this answer | |
  • 1
    this answer should have been the accepted one. – xdavidliu Apr 11 at 2:21

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.