39

I use Ubuntu 14.04 and I have a weird issue with my terminal screen which is bugging me a lot. Could someone help me with it or explain me if I'm doing something wrong or non linux-way? I have some sort of a solution but I want understand why this happens again and again.

I often copy bash commands from my notes or from the Internet and sometimes I get weird 0~ and 1~ symbols which wraps things I copied. It is very annoying and this happens in a totally random fashion.

After a long search I found out that this thing is called bracked paste mode so now I use this command printf "\e[?2004l" to fix my terminal if this mode got suddenly enabled.

Is it possible to disable this feature permanently somehow? I faced with it on all Ubuntu machines I work now. Previously I used Ubuntu 10.10 and 12.04 and I've never had such issue before.

4 Answers 4

26

You can disable bracketed paste mode.

To try it temporarily, in bash:

bind 'set enable-bracketed-paste off'

Then, if you like how that behaves, you can put the setting in your ~/.inputrc, or system-wide at /etc/inputrc (or wherever it is on Ubuntu).

5
  • 4
    All this seems to do for me is make it so I cannot type the letter "p" (and only a lower case "p"), or paste it like at all, and nothing else Mar 27, 2017 at 14:25
  • @BrianLeishman Due to the peculiar way bind parses arguments it doesn't recognise, that's what will happen if you run this command using Readline before version 7 or Bash before 4.4. This answer won't do anything useful until the next release of Ubuntu (17.04). Apr 6, 2017 at 22:02
  • The printf approach works, but it doesn't work when put in my .bashrc, and the feature somehow turns itself back on periodically. The bind approach breaks my keyboard (p key doesn't work, and putting that line in my ~/.inputrc` works, for 10 seconds, and then the console starts barfing out -enaset-enaset-... forever after 10 seconds of use. I finally just manually upgraded to bash 4.4 from source to fix the stupid problem.
    – Cloud
    Jul 7, 2017 at 16:41
  • 1
    The correct command is bind 'set enable-bracketed-paste off' (with an space instead of the first `-``. Editing only one character seems not possible.
    – done
    Jul 10, 2017 at 0:36
  • 1
    Why is the bind part of this command necessary? Does just running set enable-bracketed-paste off do the same thing? Dec 20, 2019 at 23:54
11

You can put that command in your bashrc. Then it would apply every time you open your terminal.

Just type vi ~/.bashrc and add printf "\e[?2004l" at the end and save the file with :wq

2
  • Yes, I did this at first actually :) later I just disabled this mode as @jwd suggested.
    – artemdevel
    May 6, 2017 at 19:28
  • 1
    echo 'printf "\e[?2004l"' >> ~/.bashrc does the same thing in one line, and you can verify with tail -n1 ~/.bashrc. There's no need to use vi.
    – pzkpfw
    Jan 24, 2019 at 8:06
9

To answer your original question of why this happens, here's a possible scenario:

  • My home computer had a new version of zsh that supported bracketed paste (let's call it shell A)
  • I sshed into a computer with my shell set to an older version of bash, that doesn't support bracketed paste (shell B)

Problem is, my terminal program still thinks bracketed paste is enabled when sshing from shell A to shell B, so it keeps adding the characters around your pasted content (the 0~ and 1~ bits). Shell B doesn't support them so it just passes them through unchanged. You have to tell your terminal to turn off bracketed paste by having your shell print a special escape sequence - which is what printf "\e[?2004l" does.

There are a few ways to solve the issue:

  1. If you don't care about bracketed paste at all, turn it off on shell A so it's never enabled in the first place (@jwd's answer)

  2. If you want to keep using bracketed paste on shell A, but disable on shell B, add the escape sequence to your .bashrc (@MOHRE's answer)

  3. Upgrade shell B to support bracketed paste, so it properly interprets those 0~ and 1~ characters.

Side note: if you are using GNU screen, you need to run that printf command outside of the screen. It doesn't seem to work while inside.

2
  • Thanks @rjh :) But I've never used zsh or had an issue with ssh as you described. Looks like something was just mis-configured on Ubuntu years ago.
    – artemdevel
    Jan 2, 2018 at 22:46
  • zsh doesn't seem to understand bind command. How to disable in the zsh shell A? Nov 25, 2020 at 21:20
5

I resolved it by adding the following content to my ~/.bashrc file:

if [[ $- == *i* ]]; then
    bind 'set enable-bracketed-paste off'
fi

In that way i dont get bind warnings when i execute bash scripts.

You must log in to answer this question.

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