我想清除特定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

其他回答

如果你想结合CTRL-L加上clear-history,添加到你的~/.tmux.conf:

bind u send-keys C-l \; run-shell "sleep .3s" \; clear-history

这甚至适用于MySQL shell。

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

-R \;clear-history

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

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

把这个放在你的。bashrc中:

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

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

发现这在TMUX 2.6中工作得最好,清除屏幕,滚动,但保持提示后显示。

使用ctrl - l

bind-key -n C-l send-keys C-l \; send-keys -R \; clear-history