helpful options for less


“less” the unix command, that is. The default behavior for less isn’t quite as good as it could be. I use a case insensitive search (actually ‘smartcase’) in vim, but less is case sensitive by default. You can pass -i on the command line or once less is started to get smartcase-like behavior in searches. Or you can put that in the $LESS variable in your .zshenv. My .zshenv has the following:

export LESS='-R -i --quit-if-one-screen'

From the less(1) manpage:

       -F or --quit-if-one-screen
              Causes less to automatically exit if the entire file  can  be  dis-
              played on the first screen.
...
       -i or --ignore-case
              Causes  searches  to  ignore case; that is, uppercase and lowercase
              are considered identical.  This option is ignored if any  uppercase
              letters  appear in the search pattern; in other words, if a pattern
              contains uppercase letters, then that search does not ignore  case.
...
       -R or --RAW-CONTROL-CHARS
              Like  -r,  but  tries  to keep track of the screen appearance where
              possible.  This works only if the input consists of normal text and
              possibly some ANSI "color" escape sequences, which are sequences of
              the form:

                   ESC [ ... m

              where the "..." is zero or more characters other than "m".  For the
              purpose  of keeping track of screen appearance, all control charac-
              ters and all ANSI color escape sequences are assumed  to  not  move
              the cursor.  You can make less think that characters other than "m"
              can end ANSI color escape  sequences  by  setting  the  environment
              variable LESSANSIENDCHARS to the list of characters which can end a
              color escape sequence.

The other two options are primarily git related. The -R option is so that the wonderful colored output from various git commands gets displayed properly. The --quit-if-one-screen option prevents bits of short output from commands like git log -1 from interrupting the normal flow of work. On some terminals you might need to pass -X in order to prevent the --quit-if-one-screen and the terminal’s alternate screen from hiding any output that takes up less than one screen.

Also, to echo my friend Andrew, never use “more”, there’s absolutely no point on any system where “less” is available. Seriously, just don’t do it.