Bash Keyboard Shortcuts – How to Remap Ctrl-l

bashkeyboard shortcuts

Can one remap Ctrll in bash to execute more than just clear?

I know normally it just clears the screen. I'm looking to change that to clear the screen and list my pwd like so:

Ctrll:clear;ls;

Best Answer

The bind command defines new key bindings. With the -x parameter, you can assign a shell snippet to a key. The quoting is a bit strange: the key must be quoted for the readline key parser, and the binding description must be quoted because it contains several shell special characters.

bind -x '"\C-l": clear; ls'
Related Question