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


当前回答

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

其他回答

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

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

这甚至适用于MySQL shell。

如果你在OSX上用Iterm挣扎:

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

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

如果您希望完全清除窗格,另一种选择是暂时将窗格调整为一行,清除历史记录,然后将其调整回来。这应该可以用一个tmux命令链无闪烁地工作。其优点是无论窗格中运行的是什么程序,它都可以正常工作。当然,这使得shell脚本逻辑更加复杂。

bind-key -n F11 run "
    if [[ #{window_panes} == "1" ]] ; then
        tmux send-keys C-l; sleep 0.1 ; tmux clear-history ;
    else
        restored_height=$((#{pane_height} + #{pane_at_bottom}));
        tmux resize-pane -y 1 \\; clear-history \\; resize-pane -y \${restored_height} ;
    fi
"