Smart word wrapping in `less`?

2

I use the Python package rtv as a terminal client to read Reddit. When it gets to a large text box, it calls less display the text. Currently, less wraps the words according to column width, meaning that sometimes you get cut off in the middle of the word. Is there a configuration or tweak that can make it only fold where there is whitespace?

Ed Doe

Posted 2016-07-20T18:22:57.063

Reputation: 21

No. But you can ask the author for it at [link] (http://www.greenwoodsoftware.com/less/bugs.html)

– matzeri – 2016-07-21T14:39:41.157

Answers

2

Put this in your .bashrc or similar configuration file.

export PAGER="/bin/sh -c \"fmt -s -w $(tput cols) - | less\""

ASaylover3156

Posted 2016-07-20T18:22:57.063

Reputation: 21

+1 Nice answer: pipe it through fmt first. – mach – 2020-02-03T20:44:05.883

1

One solution is to use the -S (--chop-long-lines) command line option for less. This tells less to truncate lines to the width of the screen. To view the truncated lines that are wider than the terminal, the left and right arrow keys can be used to scroll the window horizontally.

You can enable this behavior by adding -S to the command line or setting the environment variable, LESS, like this in Bash:

$ export LESS='-S'

More on word wrapping can be found in this question: How to turn off word-wrap in less

Stephen Balousek

Posted 2016-07-20T18:22:57.063

Reputation: 274

1

I use the unix toolbox for my terminal/bash viewer:

alias v='(fold -s -w75 | nl -bn -w10 | LESS= less -MINRz-4+G:1g)<'

sbin_bash

Posted 2016-07-20T18:22:57.063

Reputation: 11

What does that do? How would one use it? Please do not respond in comments; [edit] your answer to make it clearer and more complete. – Scott – 2018-12-03T20:25:53.883