Does less have an equivalent to vim's scrolloff?
Asked Answered
F

2

12

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?

Florist answered 16/6, 2011 at 17:54 Comment(1)
This is not really an answer, but you can hit u to back up one half-screen.Klingel
A
11

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"
Abortion answered 23/6, 2011 at 8:47 Comment(2)
Perfect, thank you! Now I just have to figure out why I didn't notice that on my second and third passes through man less... BTW, instead of the alias, I used the $LESS env var. Now man can pick up on the setting too.Florist
Instead of alias, add export LESS='-j 4' to your shell startup fileDeferred
T
1

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.

Tendance answered 16/6, 2011 at 17:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.