解决 zsh-autosuggestions 插件导致的粘贴卡顿

2,374 阅读1分钟

问题

zshautosuggestions插件开启的状态下,粘贴大量的内容的时候会卡顿得一个字符一个字符粘贴。

解决方案

vim ~/.zshrc

.zshrc文件中添加以下内容:

# 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
zstyle :bracketed-paste-magic paste-finish pastefinish

使配置生效

source ~/.zshrc

本文的解决方案来自zsh-autosuggestions项目的isuue