When searching for terms in less, I'd like to see lines above and below a search result. Can less be configured to do this?
Simple less usage is:
– Open file
– Search by typing "/"
– Move to new search matches with "n"
But each match is shown on the first line of the terminal. You can not see the lines that came just before a search result without moving the view back a few lines. It's tedious to do that as you skim through a file.
Best Answer
You can use the
-j
option. From withinless
, type - then j then enter a number of lines below the top of the screen for the target line to be displayed (e.g. 12).You can start
less
using this option:or set the
LESS
environment variable to include it:My
$LESS
is:You can include setting the environment variable in your
~/.bashrc
file to make it persistent.