28

When I copy from the clipboard a long string command in my iTerm, the terminal freeze for seconds.

for example, if I copy the following test and I paste in my iTerm console:

echo 'test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test' take a couple of seconds to be written in the terminal.

If the command is longer can take 15 seconds.

ZSH version '5.3'

4
  • 1
    What version of OS X/macOS are you running and on what Apple hardware? Commented Feb 15, 2018 at 13:51
  • I don't know what you consider the command's length to be in reference to "If the command is longer can take 15 seconds." but the command you've shown is 356 characters long and it pastes instantaneously on my system. If I replicate that command out to 8406 characters long, it pastes in 1 second. So, how many characters qualifies as "If the command is longer can take 15 seconds."? Also, do you get the same results if doing this under a different User on your system, even if you have to temporarily create a new User? Commented Feb 15, 2018 at 14:32
  • For me is not instant, that's the problem. The command I post takes 15 seconds to be visible on my command line. Version High Sierra 10.13.2 (But this is happening in other version too) 2.2 Ghz i7, 16Gb Ram ... Commented Feb 15, 2018 at 18:34
  • You didn't answer the last question from my other comment, which was.... Also, do you get the same results if doing this under a different User on your system, even if you have to temporarily create a new User? Commented Feb 15, 2018 at 18:42

3 Answers 3

31

The final problem is related to zsh.

oh-my-zsh is executing bracketed-paste-magic, so I ended up removing it. Because oh-my-szh doesn't have a plugin manager for this. You have to override the file: $ZSH/lib/misc.zsh

The overrides will be in this folder $ZSH_CUSTOM.

Because I don't have any override I had to create the folder first: mkdir $ZSH_CUSTOM/lib/

And create a copy of the original cp $ZSH/lib/misc.zsh $ZSH_CUSTOM/lib/.

and edit the file (use your favorite editor):

vi $ZSH_CUSTOM/lib/misc.zsh

I commented the following lines, but you can remove it or change the if condition.

#if [[ $ZSH_VERSION != 5.1.1 ]]; then
#  for d in $fpath; do
#       if [[ -e "$d/url-quote-magic" ]]; then
#               if is-at-least 5.1; then
#                       autoload -Uz bracketed-paste-magic
#                       zle -N bracketed-paste bracketed-paste-magic
#               fi
#               autoload -Uz url-quote-magic
#               zle -N self-insert url-quote-magic
#      break
#       fi
#  done
#fi

Thanks and sorry for the question description, without the knowledge that I was using zsh this made the task to help me impossible to accomplish.

More info:

6
  • 1
    thanks a lot! pasting a curl command from Google Chrome took 45 seconds! now < 1 sec :) Commented Aug 3, 2018 at 8:33
  • 1
    you could edit $ZSH/lib/misc.zsh and comment those lines too. Would be easier..
    – Nacho
    Commented Feb 27, 2019 at 14:39
  • That is what the awnser said Commented Feb 27, 2019 at 15:46
  • You could also just comment out the bracketed-paste-magic bits (inside the if is-at-least 5.1). url-quote is pretty much instant. Commented Mar 12, 2020 at 0:29
  • 2
    This is such an overkill solution. There is a much better solution found here.
    – smac89
    Commented Mar 27, 2021 at 19:31
15

In your ~/.zshrc file (create it if it's not there) you can set DISABLE_MAGIC_FUNCTIONS=true and it will disable bracketed-paste-magic which is causing this issue.

3
  • 4
    This worked perfectly to solve the slow pasting issues in iTerm2 + zsh + oh-my-zsh for me, thanks! Sounds like that flag might be disabling other functions? What other behaviours could've been changed by this? Commented Nov 12, 2020 at 11:47
  • Worked, but still slow in my case. Commented Mar 24, 2021 at 3:38
  • 1
    Years later still comes a savior.
    – k0ner
    Commented Jan 19, 2023 at 8:12
2

It seems strange that you can download and use Hyper on macOS, because it seems to be windows only.

General Performance of iTerm

The FAQ from iTerms website suggests this:

Disable transparency and blur. Use a solid background color rather than an image.

You might also want to look into how many Triggers you have activated, as they are known to decrease performance. You can find these in Settings -> Profiles -> Advanced -> Triggers.

Pasting Performance in iTerm

I couldn't replicate your issue on my computer with this short text, but making it about 20 times longer the same happens here. My guess is that iTerm thinks that you are typing and redraws the whole text every time it sees a new character. The same happens on vim in macOS and Ubuntu (see here enter link description here)

Fixing Pasting Performance in iTerm

There does not seem to be an easy fix for these performance problems. If the FAQ did not help I suggest to use this command:

pbpaste >> test.sh && chmod +x test.sh && ./test.sh && rm test.sh

pbpaste accesses the clipboard (try pbpaste on its own) and >> test.sh writes it into the file test.sh. chmod+x test.sh will allow test.sh to be run from the terminal, ./test.sh runs it and rm test.sh will remove all files called test.sh. This works exactly the same as pasting it but without the performance decrease actually pasting it brings

3
  • Are you talking about other hyper? hyper.is. No opacity or blur. No triggers :( That was promising. pbpaste lit is a very smart line but I will lose velocity by the fact I have to write the command/history/ Commented Feb 15, 2018 at 18:34
  • Sorry I found that my question was missing some information. Thanks for the time to reply! Commented Feb 15, 2018 at 19:46
  • +1 for pbpaste. I do not use triggers, and am not sure what has changed in iTerm to make pasting so slooooow.
    – verboze
    Commented Aug 7, 2020 at 15:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .