I am using zsh.

I will right-click copy something from the zsh window, and then right-click paste it. I always lose some amount of characters and the capitalization of the last character flips.


echo this is a long message

pastes as

(empty line)

this is a long messaG


vim hello.txt


m hello.tX

What could be causing this and how do I fix it?

  • Vim keybindings and an escape character in your copied text? – muru Jul 20 '17 at 2:13
  • Does your terminal support bracketed paste? – meuh Jul 20 '17 at 10:34

What is causing this is twofold:

  • Something, possibly the Z shell, told your terminal to turn on bracketed paste.
  • The Z shell is using the vicmd or viins keymap.

What is happening is this:

  1. The Z shell starts up, and issues the control sequence to turn on bracketed paste in the terminal emulator. Or maybe a text editor did this at some point, and something caused it not to issue the control sequence to turn it back off again.
  2. You paste something.
  3. The terminal emulator sends the start of bracketed paste control sequence, the pasted text, and the end of bracketed paste control sequence.
  4. The first character of the start bracketed paste control sequence is ESC, which cancels ZLE's vi insert mode and returns to ZLE's vi command mode.
  5. Subsequent characters are vi commands and do not do much, until you reach the letter o or i, which enter insert mode.
  6. The rest of the text is inserted in insert mode.
  7. The first character of the end bracketed paste control sequence is ESC, which cancels ZLE's vi insert mode and returns to ZLE's vi command mode.
  8. Subsequent characters of the control sequence do not do much.
  9. The final character of the end bracketed paste control sequence is ~, which is the vi command to swap case. This causes the final letter of the pasted text to be swapped between upper and lower case.

You fix this in one of two ways:

  • Stop the Z shell from turning bracketed paste on; as it clearly has not been configured to handle it in vicmd/viins keymaps.
  • Make bracketed paste work in vicmd/viins keymaps. How you do this depends from how you have made the Z shell recognize bracketed paste in the first place. The safe-paste plug-in rather assumes emacs keymaps, and has to be tweaked to work well with vi keymaps. But that's not the only way to get bracketed paste in the Z shell nowadays.

Further reading

  • This is both too much information and too little. I don't know what vicmd or viins is. Regardless, how do I fix the problem? I've tried the printf '\e[?2004l' and set enable-bracketed-paste off solutions I've seen in other places, but they haven't fixed it. I even experience this problem when I exit and re-ssh to my host. I haven't run vim or anything yet, I just ssh'ed into my host. Can someone please help? – Dasmowenator Dec 20 '19 at 23:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.