less (1) is a truly great tool for paging text. I use it mainly to read log files and any other text files that I think are too long to cat (1). It is also used as the default pager for man pages, so whenever you read a man page, it will be displayed using less.

Less can take a bunch of command-line options, which you can also enter while running less (like typing -i to make searches case-insensitive). However, less also reads an environment variable called LESS. This is very convenient, so in my shell, I’ve set the following:

$ echo $LESS

These options are the same as the command line options, so what these particular options sets are (interpreted from what the man page says):

  • I = case insensitive search
  • R = allow ANSI color control characters
  • X = don’t clear the screen when starting less
  • N = add line numbers

Very handy indeed, now my man pages are line numbered, but the most useful thing is the case insensitive search, which I didn’t know about before!

Update 2021-04-12 Man typically use the width of the terminal to decide when to wrap the text in man pages shown, and unless you’ve set something else up, less is used as the pager for this. When using line numbers in less, this becomes a problem. The solution came to me in the form of an answer on StackOverflow, which I adapted to fit line numbers nicely.

alias man='MANWIDTH=$((COLUMNS > 107 ? 100 : COLUMNS - 7)) man'