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


当前回答

因此,我已经从上面使用了一段时间的plu方法,但我厌倦了它的局限性(基本上,传递的⌃L是没有意义的,除非通过管道传递给一个能够理解它的程序)。

所以我在这个线程的不同答案中改进了各种方法;虽然很复杂,但这种方法适用于shell和其他命令:

# ⌃K: Clears the current pane (from <https://stackoverflow.com/a/34162098>)
bind-key -n C-k \
   if-shell "test \"$(printf '#{pane_current_command}' | tail -c 2)\" = sh" \
      "send-keys C-l ; run-shell 'sleep .3s' ; clear-history" \
      "split-window -vp 100 ; clear-history -t ! ; kill-pane"

尝试使用tail -f /private/var/log/system.log或其他东西!


警告:

这里有一个重要的注意事项:这是无形地调整正在清除的窗格的大小,如果它不是一个shell的话。这可以在一些命令行应用程序监听SIGWINCHes时触发调整大小行为;但我的理由是,这不是一个大问题,因为这些是你很可能不会试图“清除”的程序。

此外,shell引用的情况已经很混乱,并且在嵌入#{pane_current_command}时很容易变得更加混乱,所以要小心,您可能必须根据默认命令设置修改它。

这同样适用于我对命令末尾匹配“sh”的测试;如果你有一个默认的命令,比如/bin/bash——login或者一些复杂的命令,比如exec,实际的命令可能不会以“sh”结尾;使用⌃B:执行display-message '#{pane_current_command}'如果你想知道测试针对的是什么。

其他回答

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

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

这甚至适用于MySQL shell。

为了快速清除单个tmux窗格,你可以设置一个别名…

# Tmux Clear pane
alias tc='clear; tmux clear-history; clear'

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

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

这一切是这样的:

cls

clear;
tmux clear-history;

经过大量的调查和时间。我已经在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