我想清除特定tmux窗格中的所有滚动历史。


当前回答

经过大量的调查和时间。我已经在zsh和terminal.app上找到了最适合我的方式

我使用前缀-c来清除屏幕和前缀-c来清除历史记录和滚动缓冲区,上面没有留下任何行,因为我发现它很烦人。

没有活力

# clear screen
bind c send-keys 'C-l'
# clear screen and history
bind C send-keys -R \; send-keys C-l \; clear-history \; send-keys

在Vim

# check if the pane is running vim
is_vim="ps -o state= -o comm= -t '#{pane_tty}' \ | grep -iqE '^[^TXZ ]+ +(\\S+\\/)?g?(view|n?vim?x?)(diff)?$'"

# clear screen
bind c if-shell "$is_vim" "send-keys c" "send-keys 'C-l'"
# clear screen and history
bind C send-keys -R \; send-keys C-l \; clear-history \; send-keys

其他回答

如果使用clear清除屏幕,可以检查是否设置了TMUX,并相应地创建别名。

把这个放在你的。bashrc中:

if [[ $TMUX ]]; then
  alias clear='clear && tmux clear-history'
fi

比大多数更简单的方法是,我只创建了一个名为cls的shell脚本,并在我想清除屏幕和滚动缓冲区时运行它。

这一切是这样的:

cls

clear;
tmux clear-history;

正如@juanpaco正确指出的那样,clear-history是清除滚动缓冲区的命令。 我还要补充一点,我喜欢在同一个命令中清除屏幕上的内容。 发出一个send-keys -R会重置(清除)屏幕,所以我在.tmux.conf中使用了下面的代码

-R \;clear-history

这将清除屏幕和滚动缓冲区。

Ctrl-L在控制台应用程序中用于重绘屏幕。我发现当绑定到send-keys -R时,它会导致方向键在某些应用程序(如vim, mc)中不再正常工作。

为了在控制台应用程序中保留重绘功能,我使用了:

bind-key -n C-l if-shell -F '#{alternate_on}' 'send-keys C-l' 'send-keys -R C-l; clear-history'

这需要打开tmux选项的备用屏幕(默认情况下是这样)。

为什么不呢?bind -n C-l send-keys C-l