61

I often read outputs in the terminal that get wrapped as they are too long. Since there is no way that I can modify the printed output, I need to let the Terminal allow for horizontal scrolling.

Is there a modification I can make to the default OS X Terminal to disable line wrapping and allow for horizontal scrolling?

Or do you know another alternative I can use?

  • Old question, but seems to me that it is still unresolved. I am in need for the same answer, since for me i cannot further edit the output of for example GCC: gcc.gnu.org/onlinedocs/gcc/Language-Independent-Options.html With the flag -fmessage-length=0 set, i still get multi-line warning/error output. and I don't (for now). – Michael Trouw Jan 6 '15 at 20:51
42

tput did the trick for me:

tput rmam

disables line wrapping.

tput smam

enables line wrapping.

  • 9
    +1 but any way to add horizontal scrolling too? – Erik Allik Oct 21 '15 at 10:33
  • Arrow keys work for me to horizontally go to the next screen. – michid Oct 21 '15 at 14:06
  • 5
    I don't see how to use the arrow keys... they don't work for me. This solution seems to just truncate the lines to the width of the current window. When I make the window bigger there is just empty space to the right of lines that I know contain more characters. Still, this solution is useful for my purposes since I'm displaying logs and the information on the far right is inconsequential at the moment. – Jason Jan 28 '16 at 14:54
  • 2
    nice find! added myself a couple of memorable zsh aliases: alias wrapon='tput rmam' & alias wrapoff='tput smam' – Chris J Allen Apr 12 '16 at 10:57
  • 2
    talk about obfuscated commands – Andy Oct 19 '17 at 15:42
6

iTerm 2 doesn't seem to support disabling line wrap either. You might just use less or cut though:

less /var/log/system.log
expand /var/log/system.log | cut -c 1-$COLUMNS
less -s <<< "$(osascript -e 'tell app "Terminal" to contents of window 1')"
6

Pipe the output through less -S:

   -S or --chop-long-lines
          Causes lines longer than the screen width to be chopped (truncated)
          rather than wrapped.  That is, the portion of a long line that does
          not fit in the screen width is not shown.  The default is  to  wrap
          long lines; that is, display the remainder on the next line.

I tried to explain what might be going on here, though this won't result in a way to scroll horizontally with a scrollbar, as you seem to want.

1

If you are (as others suggest as a solution, although I think you asked about direct output) then redirect output to a somename.log file and open it with Applications>Utilities>Log-Viewer (or from commandline as open somename.log).

It's not in the terminal but I found the log viewer to the one best suited to deal with large amount of output (searching, scrolling, filtering).

  • I think you mean the Console.app, right? There is no Log Viewer.app in the Utilities. However, the console also wraps, the only difference is that long lines are contracted by default. You have to click them to read everything - so, this won't help unfortunately. – gentmatt May 27 '13 at 17:02
0

Depending on what you are trying to stop wrapping you could use vim. So launch vim on the file with the long lines, and then type:

:se nowrap
  • 1
    This won't help, since I'm not reading files. I'm reading network information via lsof. – gentmatt May 27 '13 at 16:57
0

Use cut

myscript | cut -c -100

You must log in to answer this question.

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