less
less copied to clipboard
Line wrapping: break at space
Currently, less's wrapping will display lines until the terminal's end and will then jump a line and put text that immediately follows. This splits words in the text. Could it be possible to add an option to instead make the line wrapping break at space ? That is, whenever the next word doesn't fit in the current line, it will be put on the next one with what follows.
Here is a hack that replicates the behavior I want:
export LESSOPEN="| fold -s -w $(tput cols) %s"
and then just open the desired text file. Would be nice to have this natively in less, because it breaks when less reads from stdin. Basically,
less file.txt
Works, but not
cat file.txt | less
You can make a LESSOPEN preprocessor work on stdin by adding a "-" after the pipe symbol. That is, you can use:
export LESSOPEN="|- fold -s -w $(tput cols) %s"
See the last paragraph in the man page in the INPUT PREPROCESSOR section.
Right, this works, now I completely read this section. But I still think it would be nice to have a native option instead of using some hack. What do you think ?
@TheBrainScrambler A hack? This is how less's manual defines it :-)
I added this many years ago, but Mark never said much about it and I stopped trying.
In my opinion Unix is like a toolbox, you combine different tools together. You have fold(1), use it!
@adoxa Hi Jason, in 57dacf280a4e53a0aa883d5153702593298734f4 I've finally gotten around to integrating your word-wrapping change. Let me know if you see any issues with it.
Until now I had been of the philosophy that a pipeline with fold or something similar would suffice, but this feature has been requested often enough, and it's a straightforward enough change, that I think it's worth building it into less.