简体   繁体   English

在 Bash 中将 clear 绑定到 ^l

[英]To bind clear to ^l in Bash

I would like to have Ctrl-l for clear in my Bash.我想在我的 Bash 中clear Ctrl-l

How can you bind Ctrl-l to clear in Bash?如何在 Bash 中绑定Ctrl-lclear

Put this in your ~/.inputrc :把它放在你的~/.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 ). (假设“清除”的意思是“清除当前输入行”;如果您的意思是“清除屏幕”,则放置clear-screen而不是backward-kill-line )。

in a particular case where the clear-screen didn't work for me either, I found out that putting in ~/.bashrc the line: bind -x $'"\\Cl":clear;'clear-screen对我也不起作用的特定情况下,我发现在~/.bashrc中放入一行: bind -x $'"\\Cl":clear;' was better than "\\Cl":'clear\\n' in ~/.inputrc because it cleared the screen and left the currently typed command in place;~/.inputrc "\\Cl":'clear\\n'更好,因为它清除了屏幕并将当前键入的命令留在原地; for example ( ^L show where I hit the combo):例如( ^L显示我击中组合的位置):

With "\\Cl": clear-screen in ~/.inputrc :使用"\\Cl": clear-screen in ~/.inputrc

user@darkstar:~$ date^L
user@darkstar:~$ date
user@darkstar:~$ ^L
user@darkstar:~$ 

With "\\Cl":'clear\\n' in ~/.inputrc :~/.inputrc使用"\\Cl":'clear\\n'

user@darkstar:~$ date^L
-bash: dateclear: command not found
user@darkstar:~$ ^L
# screen effectively redrawn

With bind -x $'"\\Cl":clear;'使用bind -x $'"\\Cl":clear;' in ~/.bashrc :~/.bashrc

user@darkstar:~$ date^L
# screen redrawn and the top line is now:
user@darkstar:~$ date

And for now I have not been able to get the same result as bind -x using only the inputrc file...而现在我还无法获得bind -x仅使用 inputrc 文件的bind -x相同的结果......

Edit编辑

I found that in some cases where clear-screen wasn't working for me were caused by my attempts to get more colors in the CLI.我发现在某些情况下, clear-screen对我不起作用是因为我试图在 CLI 中获得更多颜色。 For example I had the issue with TERM=xterm-256color (or screen-256color , etc.) and removing the -256color part solved the problem.例如,我遇到了TERM=xterm-256color (或screen-256color等)的问题,删除-256color部分解决了问题。

I have not yet found a way to get a 256 colors term working along CTRL + l (in xterm, urxvt, etc).我还没有找到一种方法来获得一个 256 色的术语,它可以与CTRL + l一起工作(在 xterm、urxvt 等中)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM