views:

413

answers:

1

I would like to have Ctrl-l for clear in my Bash.

How can you bind Ctrl-l to clear in Bash?

+3  A: 

Put this in your ~/.inputrc:

C-L: backward-kill-line

(assuming by "clear" you mean "clear current input line"; if you mean "clear screen" then put clear-screen instead of backward-kill-line).

chaos
I mean the latter one. -- I put `C-L clear-screen` to ~/.inputrc unsuccessfully. This suggests me that ~/.inputrc is not sourced by Bash. However, Bash does not like if I source the file at .bashrc. -- Where should I put the code?
Masi
`.inputrc` isn't *sourced* by bash, exactly; it doesn't contain `bash` commands, it contains readline library configuration directives. The environment variable INPUTRC can be used to override the default location of `~/.inputrc`; conceivably that may be set. And you do need to start a new `bash` in order for it to take effect; it won't affect existing sessions.
chaos
On my system C-L defaults to clear-screen.
Dennis Williamson
@Dennis: It did that for me half a year ago. But after using Zsh for that period, it does not work for some reason. --- This suggests me that there must be some other file than .inputrc which needs to be changed to get `clear` work.
Masi
Well, that isn't the case for me. `C-L: clear-screen` in `~/.inputrc` works fine on my logins. I don't know what's going on with yours.
chaos