Question

How do I override Control+W in bash within my .inputrc? The following on its own doesn't work:

"\C-w": forward-word

It does work when I add stty werase undef but then the 's' key is mysteriously disabled!

Was it helpful?

Solution

You need to use the option set bind-tty-special-chars Off in your .inputrc file in order to bind ^W like that. The reason is that:

Readline, beginning with version 5.0, reads the stty special character settings and binds them to their readline equivalents each time readline() is called from bug-bash mailing list

The bind-tty-special-chars option was introduced in 5.1 in order to work around this feature. Readline Changes - search for the option

set bind-tty-special-chars Off
"\C-w": forward-word

The slightly older-school method involves .bashrc like:

stty erase undef
bind '"\C-w": forward-word'
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top