I want less's linewrapping to be smarter... when lessing through text it's wrapping lines in such a way that words get broken up which makes reading difficult. The smart way would mean only breaking lines on a "space" character.

Is this possible?

In reading the man page and browsing the internet I surprised to see no other mention or inquiry of this.

If less can't do this is there another pager that can?


  • Ideally this would effect could be toggled with a flag like --cleanwrap.
  • Using this on stdin like some-report.py | less -i --cleanwrap is important.
  • Ideally the pager will adjust to screen/terminal(tmux pane) resizing... maybe less isn't the right tool? This could be sacrificed if the above features were possible :(
  • to my surprise: I started using vim with a custom vimrc for paging. Does a better pager exist in Linux?
    – alec
    Sep 21, 2020 at 22:53

1 Answer 1


less doesn’t have a built-in way of doing this, but if you use lesspipe, you can extend that to wrap files by extension.

The following, saved as ~/.lessfilter, will word-wrap .txt files at 80 columns:


case "$1" in
    *.txt) fold -s "$1";;
    *)     exit 1;;

exit 0

Make this executable, then make sure less is using lesspipe:

eval "$(lesspipe)"

and you should find that less ...txt will word-wrap.

This can be extended to handled other extensions, adjust the width to the terminal width, etc.

  • What about data piped to less? I was hoping for a flag or switch like --smartwrap.
    – alec
    Sep 21, 2020 at 15:51
  • Is "wrap files by extension" the only possibility available in your suggestion?
    – alec
    Sep 21, 2020 at 16:25
  • 1
    No, you can filter data piped to less, but it’s harder to figure out what to do automatically... Sep 21, 2020 at 16:34

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.