Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save magicdude4eva/2d4748f8ef3e6bf7b1591964c201c1ab to your computer and use it in GitHub Desktop.
Save magicdude4eva/2d4748f8ef3e6bf7b1591964c201c1ab to your computer and use it in GitHub Desktop.
zsh-syntax-highlighting paste performance improvement
Add the following in .zshrc:
...
plugins=(osx git zsh-autosuggestions zsh-syntax-highlighting zsh-nvm docker kubectl)
...
### Fix slowness of pastes with zsh-syntax-highlighting.zsh
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
### Fix slowness of pastes
source ~/.zsh/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
...
@vladyio
Copy link

vladyio commented Nov 11, 2020

THANKS!

@konekoya
Copy link

Thanks for this!

@Velosofy
Copy link

Velosofy commented Nov 14, 2020

In my case,
WSL Terminal is faster than before ( still took like 5s+ )
but in VSCode terminal, it only took 2secs

Weirdly, in WSLTerminal you can see the word is being pasted, but not in VSCode
Any insight ? Thanks

@daxmc99
Copy link

daxmc99 commented Jan 20, 2021

Not sure if sourcing ~/.zsh/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh is needed. The original fix didn't need that step.

@kirschem
Copy link

Great, thx, works wonders! Sourcing was not needed for me.

@HannesHil
Copy link

HannesHil commented Jan 24, 2021

Thanks, works quite well.

@mtHuberty
Copy link

Worked for me too. Thanks! (Didn't need the source statement at the end though)

@mrcomoraes
Copy link

Thanks. It's worked for me.

@StrangeRanger
Copy link

I found that this worked as well: zstyle ':bracketed-paste-magic' active-widgets '.self-*'. I found the solution here: zsh-users/zsh-syntax-highlighting#295 (comment).
@magicdude4eva Do you know if there are any major differences between your solution and the one provided in the issue in the link I provided?

@magicdude4eva
Copy link
Author

magicdude4eva commented Mar 18, 2021

I do not think so - I just tried a number of things until performance was alright. I have honestly not looked at this since 2019. Surprised that this is seemingly not fixed and requires still a workaround.

@liranh85
Copy link

Worked perfectly for me - no more lags when pasting from the clipboard! 🎉

@Write
Copy link

Write commented Jun 14, 2021

As someone new to zsh && oh-my-zsh, thanks !

@spielhoelle
Copy link

Thanks worked

@GussSoares
Copy link

It's amazing! thank you so much for this, to paste now is so fast!

@GussSoares
Copy link

It's amazing! thank you so much for this, to paste now is so fast!

@shubhammatta
Copy link

Thanks! it worked.

@avatar-lavventura
Copy link

Are we required to source zsh-syntax-highlighting ?

@kohane27
Copy link

Are we required to source zsh-syntax-highlighting ?

I've disabled sourcing zsh-syntax-highlighting.zsh and the fix still works.

@ksingh7
Copy link

ksingh7 commented Feb 3, 2022

Thanks, worked like charm @magicdude4eva when I visit your neighborhood, beer is on Me. Cheers

@brianbc2021
Copy link

Thanks! works for me :)

@yinlongsea
Copy link

it works for me, thanks

@ToontjeM
Copy link

ToontjeM commented Dec 5, 2022

Please submit to the zsh-syntax-highlighting maintainer as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment