修复由于 zsh-autosuggestions 造成的粘贴慢

使用 zsh 在开启 zsh-autosuggestions 插件的时候,粘贴命令会像打字一样,尤其是长段的命令,需要等很长时间

官方有一个 issues 专门来讨论这个问题:https://github.com/zsh-users/zsh-autosuggestions/issues/238

解决办法:将以下代码粘贴到 .zshrc 文件中即可

1
2
3
4
5
6
7
8
9
10
11
# This speeds up pasting w/ autosuggest
# https://github.com/zsh-users/zsh-autosuggestions/issues/238
pasteinit() {
OLD_SELF_INSERT=${${(s.:.)widgets[self-insert]}[2,3]}
zle -N self-insert url-quote-magic # I wonder if you'd need `.url-quote-magic`?
}

pastefinish() {
zle -N self-insert $OLD_SELF_INSERT
}
zstyle :bracketed-paste-magic paste-init pasteinit