2

I work with TextMate and R over the terminal. When pasting a lot of code (CMD+C/CMD+V, e.g. 60 lines) it sometimes happens that few characters in the code are scrambled, which then leads to error messages and wrong code execution.

For example:

col <- ifelse(...

is turning into

col < col < cse(...

or

onlyDF

is turning into

oalyDF

These character-replacements seem very random and it is difficult to predict when it happens.

The problem is also described here for iterm2: https://gitlab.com/gnachman/iterm2/issues/3160

The explanation provided there is that it is a bug in bash that can lead to buffered input to get lost due to paste speed.

Has anyone experienced these problems and found a work-around for the native terminal app in Mac OS? (e.g. by modifying the paste speed, if that is possible in terminal)

marked as duplicate by Monomeeth Sep 4 at 5:00

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • If you read to the very bottom of that 2 year old thread, there's an entry that states: To change the speed that "paste slowly" pastes.... – Allan Feb 3 '18 at 17:00
  • indeed – but I am working with terminal, not iTerm. Since the problem seems to affect both apps, I am wondering if there is also a solution for the native terminal. – grueb Feb 3 '18 at 17:05
  • What program is running in the foreground in the terminal when you are pasting into it? – thrig Feb 3 '18 at 21:22
  • you can use Iterm2, Paste slowly in edit -> paste special -> paste slowly, see https://gitlab.com/gnachman/iterm2/issues/3160#note_1168791 – jk2K Sep 4 at 2:40
3

When I need to paste a lot of text into a Terminal application window, I use the cat command to transfer the text to a file. For example, I would enter the command below before pasting the text with the +V key combination.

cat >myfile.txt

When finished pasting text, enter the control+D key combination. This will terminate the cat command.

Note: The control+D key combination must be entered at the beginning of a line. If not at the beginning of a line after pasting the text, then press the return key before entering the control+D key combination.

  • You can do it even more directly with pbpaste >myfile.txt. No need for Command-V, Control-D, etc. – Gordon Davisson Oct 27 '18 at 17:20
  • @Gordon Davisson: You should post an new answer. – David Anderson Oct 27 '18 at 20:12
2

You can use the pbpaste command to get the text in the pasteboard without going through the vagaries of the terminal driver, buffer overruns, etc. To put the cut text into a new file, use:

pbpaste >myfile.txt

To append, use >>, etc. Similarly, you can feed the pasteboard's contents to other commands as input:

pbpaste | somecommand

And if you use the vi editor, you can insert the pasteboard's contents into your file with:

:r !pbpaste

BTW, there's also a corresponding pbcopy command to put text into the pasteboard. Unlike standard file redirections, you can use this to nondestructively modify the contents of the pasteboard "in place":

pbpaste | sed 's/foo/bar/' | pbcopy

...and if you want to see the output as well:

pbpaste | sed 's/foo/bar/' | tee /dev/tty | pbcopy

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