4

Tabs are getting removed from text that I paste into the Terminal. Any suggestions?

An example of my use case is to paste sections of TSV files into a remote ssh session terminal, bypassing the tedious multi-hop scp process.

This is not about using other editors/tools (e.g. emacs/vi) and I am already aware of how to enter a single tab char via CTL-Tab. These do not meet the need.

2
1

This is tricky, because you have to consider not only the pasting operation, but also the original copying step.

Indeed in OS X it seems to be impossible to paste a tab character in the Terminal app. On the other hand, pasting a tab into some other app (such as TextEdit) works fine.

On Linux, it's kinda the opposite. Pasting tabs works fine; but copying them in the first place is a problem. It depends on where you're trying to copy them from. If you simply dump the contents of a file onto your terminal (with cat for example), any tab characters get expanded: replaced with some number of spaces. If you then tried to select the text and copy from the terminal output, it would be too late. Note that it's not the cat program itself that does the expansion, it's the lower-level device driver or terminal emulator.

It's instructive to consider OS X again. On OS X, the stty command has an option to control whether tabs should be expanded on output or not. If you run stty oxtabs and then try to dump some text to Terminal, you would see that the tabs get expanded, as they unconditionally do on Linux, and if you try to copy/paste that output the tabs are replaced.

1
3

If you just need to insert a tab, you can press control-v and tab.

To temporarily allow pasting tabs in bash, run:

bind '"\t":self-insert'

To re-enable tab completion, run:

bind '"\C-i":complete'

If you're pasting text to emacs, you can use a function like this instead of command-v:

(defun pbpaste ()
  (interactive)
  (shell-command-on-region
    (point)
    (if mark-active (mark) (point))
    "pbpaste" nil t))
3
  • An example of my use case is to paste sections of TSV files into a remote ssh session terminal, bypassing the tedious multi-hop scp process. So this answer does not actually address my use case. – WestCoastProjects Dec 13 '13 at 12:54
  • @javadba: In that case you should probably explain your use case in more detail. What sequence of ssh sessions, shells, etc are you trying to pass a tab through? Where is it going on the other end: into a file, into a shell, into stdin of some process, etc? – Gordon Davisson Dec 13 '13 at 15:33
  • @GordonDavisson updated the question – WestCoastProjects Dec 13 '13 at 18:21
1

In both linux and OS/x there does not appear to be a means to paste tabs into a terminal. If anyone (eventually) comes up with a solution please feel free to add the answer.

1

Sort of a workaround (at least in Linux)

  • v=$(cat)
  • then paste your text
  • then ctrl-D to close the 'cat' command
  • and there you have your text with tabs in $v, which you can output with echo "$v"
1
  • Maybe this works on *nix but i'm on macos where it does not. Will upvote anyways as an interesting idea – WestCoastProjects Nov 6 '19 at 3:45

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.