When you type
$ man grep on your terminal, the navigation is different than it is when you look at a file in Safari. For instance, you might be wondering how to close the man file. If you jumped for
⌃ C then you’re not alone. However, pressing
q is the keybinding to exit when inside a
The reason that the keybindings are different, is because a
man page is rendered using a terminal pager called
Therefore the keybindings when you type
$ man grep are identical to the keybindings when you type
$ less bigfile.txt
If you don’t know the
less keybindings, then congratulations! I didn’t either so I’ve provided them below.
Conveniently, they are pretty compatible with
J keys are used to scroll down & up respectively, which is the same as vim’s binding to move the cursor down & up. Since less is read-only, the cursor is always pegged at the last row. However,
vim's scrolling keys
⌃ E and
^ K work in
less as well (but the CTRL key is optional).
|E or J||Scroll down 1 line|
|Y or K||Scroll up 1 line|
|<||Jump to the beginning of the file|
|>||Jump to the end of the file|
|5 G||Go to line 5|
You can type
/info to search the current screen and below for
||Search for the regex
||Search for the regex
|N||Find the next instance of
|⇧ N||Find the previous instance of
Tip: This search functionality supports regular expressions, which lets you make more powerful searches.
Why is it called
As the aphorism goes, “less is more”. This saying is true in our daily lives, but it’s also true for your computer.
In the 1980s, a popular terminal pager called
more was frequently used to read in text line-by-line on a computer’s terminal. The problem with
more, however, was that
more is not able to scroll backwards. As a result, Mark Nudelman wrote a “backwards
This program, he cleverly named
less because “
LESS environment variable
Any options you want to add to
less on every invocation can be done by adding these options to the environment variable
LESS. Each option can be separated by a
$ for clarity. An example is provided below.
less to always squeeze multiple newlines and center search results
export LESS='$ s $ -j .5 $'
Centering Search Results
If you don’t like how searching for a string in
less causes it to appear at the top of the pager, there’s a setting that centers it. Add the option
-j.5 to the command to cause this, or add it to the environment variable
less -j.5 ./example.txt