Zsh 清除回滚缓冲区

Zsh 清除回滚缓冲区

使用 BashCtrlL将清除屏幕但不会回滚缓冲区。过去我通过使用以下方法解决了这个问题:

tput reset

但是我注意到这个命令不会用 Zsh 清除回滚缓冲区。那么,它是如何做到的呢?

答案1

function clear-scrollback-buffer {
  # Behavior of clear: 
  # 1. clear scrollback if E3 cap is supported (terminal, platform specific)
  # 2. then clear visible screen
  # For some terminal 'e[3J' need to be sent explicitly to clear scrollback
  clear && printf '\e[3J'
  # .reset-prompt: bypass the zsh-syntax-highlighting wrapper
  # https://github.com/sorin-ionescu/prezto/issues/1026
  # https://github.com/zsh-users/zsh-autosuggestions/issues/107#issuecomment-183824034
  # -R: redisplay the prompt to avoid old prompts being eaten up
  # https://github.com/Powerlevel9k/powerlevel9k/pull/1176#discussion_r299303453
  zle && zle .reset-prompt && zle -R
}

zle -N clear-scrollback-buffer
bindkey '^L' clear-scrollback-buffer

clear添加和zle .reset-prompt && zle -R是为了确保它适用于多行提示,这一点很重要。

参考

答案2

  • Cmd-K
  • 菜单/编辑/清除开始

相关内容