Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does less have an equivalent to vim's scrolloff?

Tags:

less-unix

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?

like image 628
valadil Avatar asked Jun 16 '11 17:06

valadil


2 Answers

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"
like image 61
Flimzy Avatar answered Oct 24 '22 05:10

Flimzy


Not sure if you can make less do this by itself, but did you know you can use Vim in place of less as your pager? There's a macro in the Vim installation macros/ directory called less.vim. Copy it to your own .vim/macros directory to enable, then alias less in your .bashrc (or whatever your shell)

# example:
alias less='/usr/share/vim/7.x/macro/less.sh'

EDIT Unfortunately I just tried this myself and it ignores the scrolloff by default. You could modify the less.sh to set scrolloff=3 at launch.

like image 36
Michael Berkowski Avatar answered Oct 24 '22 05:10

Michael Berkowski