I would like to modify the search behavior when inside less: By default next match is shown at the very top line. Instead show me next match of word at 5th line of screen/ show 4 lines before match. Like so:

yadda yadda
more yadda
more of the yadda
Some sentence with word (<-- match!)
yadda goes on

This is somewhat similar to grep -B4: print NUM lines of leading context before matching lines.

Less is by default my manpages pager.


Type -j5 Enter to set the target line for searches to 5 (the default setting is 1 which is the top line).

To make this the default, add -j5 to the default less options. One way to do that is to include -j5 in the LESS environment variable set e.g. in your .profile or .environment. Another way is to put

LESS = -j5

in ~/.lesskey and run the command lesskey.

|improve this answer|||||
  • Thank you. Now that you me point me to it: You can position the screen relative to the match depending on your screen size. .1 puts the match at the first tenth of the screen height. Thanks again! – d-nnis Apr 5 '19 at 10:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.