user7055375
user7055375

Reputation:

Getting strange characters when pasting into my iterm2 terminal

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?

Upvotes: 173

Views: 79412

Answers (11)

Ram Patro
Ram Patro

Reputation: 131

$ printf '\e[?2004l'

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

00~printf '\e[?2004l'01~

Upvotes: 8

logan
logan

Reputation: 8346

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

Upvotes: 1

Sahil
Sahil

Reputation: 125

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

Upvotes: -1

Arjun Sankarlal
Arjun Sankarlal

Reputation: 3141

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

Upvotes: 267

Jianwu Chen
Jianwu Chen

Reputation: 6023

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

Upvotes: 92

n.caillou
n.caillou

Reputation: 1342

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.

Upvotes: 2

user3429211
user3429211

Reputation: 171

I think it's a bracketed paste issue

  1. Edit -> Paste special -> Advanced Paste

  2. Uncheck "Bracketed paste mode"

  3. Restart the terminal

Upvotes: 17

whiletrue
whiletrue

Reputation: 11075

Solution in my case:

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

Upvotes: 62

dbenhur
dbenhur

Reputation: 20408

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.

Upvotes: 7

Kun Zhao
Kun Zhao

Reputation: 31

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

Upvotes: 3

Robert Sigler
Robert Sigler

Reputation: 139

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.

Upvotes: 13

Related Questions