8

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
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.

1 Answer 1

9

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

#env
LESS = -j5

in ~/.lesskey and run the command lesskey.

1
  • 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, 2019 at 10:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .