28

Is it possible to copy a "block" of text from a terminal window without having to copy entire lines?

Example:

enter image description here

Say I just wanna copy the text I’ve circled in the image above, is this possible? Or do I also have to copy everything to the left of the block I want to copy?

39

You should be able to do this by holding the option key down while doing it. This changes the cursor to a '+' sign and allows you to select any rectangular area of text.

See screenshot below:

enter image description here

If you look at the above image closely, you'll see in the left window I've highlighted a block of text in Terminal and in the right window I've been able to paste this text into a new TextEdit document.

  • 3
    This doesn't work in iTerm but works fine in Terminal. – jmh Dec 14 '18 at 15:14
13

When using iTerm2, you can either use Cmd+Option+mouse to perform vertical/block selection, which transforms your cursor into a cross, similar to Terminal.app.

Or you can use copy mode:

  • Cmd+Shift+C to enter copy mode
  • Ctrl+v to enter vertical/block mode
  • Move the cursor using the cursor keys on the keyboard (see link for more movement options)
  • Once you’re done, use Ctrl+k, y to copy the selection.
10

You might also try using awk to limit the shell output to what you want. You could then even pipe it to pbcopy

  • 2
    Or just cut -c 56- or so. – Wildcard Dec 15 '18 at 2:46

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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