Search code examples
less-unix

Does less have an equivalent to vim's scrolloff?


I have scrolloff set to 4 in vim. This means that when I scroll up or down, there are 4 lines between the line I'm on and the bottom or top of the screen.

When I use less, usually to view a manpage, I use / to search for text. If I'm looking for a command line option that does something and I search for the term 'something' usually 'something' shows up in the paragraph explaining a command, and the command line switch is a line or two above that, so I have to scroll up to see it. Any ideas for how to make less act more like vim in this one case?


Solution

  • I believe you want the -j option. It doesn't seem to have a bottom-or-top mode, but rather a bottom-mode or top-mode. For instance:

    less -j 4
    

    Will always display your search term on the 4th line (from the top), whereas

    less -j -4 
    

    Will always display your search term on the 4th line from the bottom.

    And of course, you can use alias to make your preference the default, by adding this to your .bashrc, for instance:

    alias less="less -j 4"