I'm using the native bind command from bash, but it seems that it doesn't work with alt keys combination:

bind "M-q:echo 'hello'"

tried the key code version as well:

bind "^[q:echo 'hello'"

This one being found using the Ctrl+V key and then typing Alt+Q.

I'm aware of other alternatives such as sxhkd, using other shells with better keys binding support etc, but I would prefer using bash for this aswell.

1 Answer 1


Well, it seems i managed to find the answer:

bind '"\eq":"echo 'foobar'"'

where \e is the keycode for Alt/M, and thus do what the post described...

This only post the command and do not directly execute it, though if one want that, there only need to add \n at the end, like so:

bind '"\eq":"echo 'foobar'\n"'

Seems like the recommended way to find the keycode (which is done by using the Ctrl+V combination) didn't work in this instance and gave the wrong keycode. Though, using bind -p to see existing keybinding is a good way to figure things out.

You must log in to answer this question.

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