ZSH:如何默认启用本地历史记录
在 zsh 中(尤其是使用 oh-my-zsh 时),默认的历史记录是全局的,即所有 shell 共享。如果你在多个终端会话中工作并期望每个会话有独立的历史记录,这通常会很奇怪。
要修复此问题,将以下内容追加到 ~/.zshrc 文件:
enable_local_history_zsh.sh
# 本地历史记录 - https://superuser.com/a/691603/285486
bindkey "${key[Up]}" up-line-or-local-history
bindkey "${key[Down]}" down-line-or-local-history
up-line-or-local-history() {
zle set-local-history 1
zle up-line-or-history
zle set-local-history 0
}
zle -N up-line-or-local-history
down-line-or-local-history() {
zle set-local-history 1
zle down-line-or-history
zle set-local-history 0
}
zle -N down-line-or-local-history
bindkey "^[[1;5A" up-line-or-history # [CTRL] + 光标上
bindkey "^[[1;5B" down-line-or-history # [CTRL] + 光标下Check out similar posts by category:
Linux
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow