Getting strange characters when pasting into my iterm2 terminal

Copy PastePasteIterm2

Copy Paste Problem Overview


I'm using iterm2 v 3.0.15 on Mac Sierra. I'm having trouble cutting and pasting from other places (e.g. text on a web page) into my terminal. For instance, I highlight some text from a web page, press Command + C, go to the terminal, and then press Command + V, I get

localhost:myproject nataliab$ 00~on the next01~

Notice the "00~" and "01~" in front of and behind my text. I do not see these characters when I cut and paste into a text editor or other places. How do I eliminate these special characters from appearing when I cut and paste into my iterm2 terminal?

Copy Paste Solutions


Solution 1 - Copy Paste

In the terminal window type reset, and press enter. And now, try pasting contents in terminal, it should work properly.

Solution 2 - Copy Paste

Solution in my case:

Paste printf '\e[?2004l' to the iTerm2 terminal and press enter afterwards.

Solution 3 - Copy Paste

To permanently disable bracketing paste mode, open the Preference, search "bracketing", uncheck "Terminal may enable paste bracketing"

Solution 4 - Copy Paste

I had the same issue, and was unable to figure out why the problem was happening, but closing iTerm2 with Command + Q and reopening it fixed the problem.

Solution 5 - Copy Paste

I think it's a bracketed paste issue

  1. Edit -> Paste special -> Advanced Paste

  2. Uncheck "Bracketed paste mode"

  3. Restart the terminal

Solution 6 - Copy Paste

I recently started encountering this behavior in iterm2 as well. Killing and restarting a session fixes it, but loses context. I found this comment about bracketed paste mode and tried printf '\e[?2004h' to exit bracketed paste mode and repair the terminal and it worked well for me.

Solution 7 - Copy Paste

$ printf '\e[?2004l'

It solved my issue. but the funny part is when i pasted the above command, it also pasted as below

00printf '\e[?2004l'01

Solution 8 - Copy Paste

Adding set t_BE= to .vimrc to disable bracketed paste mode should fix this. you may refer: https://gitlab.com/gnachman/iterm2/issues/5698

Solution 9 - Copy Paste

I can't guarantee the conditions of this fix because I had been fiddling for a while with the solutions above, but what fixed the issue for me was to go to:

iTerm2 → Preferences → Keys → double-clic to edit the target of ⌘v → Under Speed, set Chuck Size to 256B and Interchunck delay to 100ms.

Solution 10 - Copy Paste

I had to do shell-->Hard Reset to make it work immediately

Solution 11 - Copy Paste

printf '\e[?2004h' should solve the issue; also make sure to remove the trailing and starting junk characters.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser7055375View Question on Stackoverflow
Solution 1 - Copy PasteArjun SankarlalView Answer on Stackoverflow
Solution 2 - Copy PastewhiletrueView Answer on Stackoverflow
Solution 3 - Copy PasteJianwu ChenView Answer on Stackoverflow
Solution 4 - Copy PasteRobert SiglerView Answer on Stackoverflow
Solution 5 - Copy Pasteuser3429211View Answer on Stackoverflow
Solution 6 - Copy PastedbenhurView Answer on Stackoverflow
Solution 7 - Copy PasteRam PatroView Answer on Stackoverflow
Solution 8 - Copy PasteKun ZhaoView Answer on Stackoverflow
Solution 9 - Copy Pasten.caillouView Answer on Stackoverflow
Solution 10 - Copy PasteloganView Answer on Stackoverflow
Solution 11 - Copy PasteSahilView Answer on Stackoverflow