For reference, some Less options we're going to be using:
-S
, less doesn't wrap lines;-F
, less auto-exits if output less than a page-R
, less honors color control codes-X
, disables termcap. This is set by git by default, but it breaks scrolling for some reason
- Make sure you're using the most recent version of both software. (The versions that are compiled by Apple and included in macOS are non-standard.)
brew install less
brew install git
- Set the
LESS
enviroment variable. This variable includes the flags that are passed to Less by default. In my.zshrc
:
export LESS="SF"
- Setting this variable disables the git defaults, so we have to reset Git's pager setting.
git config --global core.pager "less -RF"
If using these Less settings, by default in iTerm2, opening
less
and scrolling down will replace previous lines of your terminal scrollback with the file contents. I find this behavior unintuitive and undesired. It can be disabled by un-checking "Save lines to scrollback in alternate screen mode" in iTerm2 preferences > Profile > Terminal. (Ref)