Zshはスクロールバックバッファをクリアします。

Zshはスクロールバックバッファをクリアします。

Bashを使用すると、CtrlL画面は消去されますが、バッファを後ろにスクロールしません。私は過去に以下を使用してこの問題を解決しました。

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が重要です。

引用する

おすすめ記事