0

Sometimes when I copy+paste into my spacemacs over SSH, I get some random garbage that seems to be due to spacemacs interpreting some of the pasted content as commands. In vim, my workaround is to run r! cat, paste what I want into the cat command, then Ctrl-D to exit. When I run M-x shell-command ENTER cat ENTER, however, I get (shell command succeeded with no output) immediately, and no prompt.

What is the right way to get the equivalent of r! cat from emacs (or spacemacs, in particular)?

  • What exactly happens when you copy and paste? What does the random garbage look like? Does it also show up when you use vim over ssh? What is the difference between pasting directly and passing it through cat? I, for one, would appreciate more detail about what is going wrong and how exactly your workaround solves the problem. – NickD Aug 12 at 18:24
  • @NickD: For one example, if I paste in text that contains my evil-escape-key-sequence, it leaves insert mode and interprets the rest of the pasted text as normal mode commands. Or if I paste text with unbalanced parens, smartparens inserts some unwanted close parens at the end of the pasted text. – Patrick Collins Aug 12 at 18:29
  • So in the first case you edit the input to cat and delete the key sequence and in the second case you add/delete parens to make it balanced, before you signal EOF to cat? – NickD Aug 12 at 18:36
  • @NickD -- no, at least with vim, it doesn't interpret the piped cat output as keyboard input, so the auto-formatting doesn't fire. – Patrick Collins Aug 13 at 1:10
0

Doing that with cat is a real kludge; the right solution is to turn on bracketed paste mode in your terminal emulator. Your terminal emulator knows when you are pasting, so it is supposed to send an escape sequence at the start of the paste and another at the end. Emacs can then treat the text in the middle as raw text rather than commands.

Every terminal emulator has a different way of configuring this, but Emacs should auto-detect it once you do.

| improve this answer | |

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.