improve man page search

4

There is one little thing annoying me in man pages. When I search for text using '/' command the line where the text is found is positioned at the top of the screen. I find it inconvenient because when I search for text I want to see it in the context which also includes the a couple of lines before the found text.

Is there a way to tell the man pager not to scroll the screen all the way to the top during search?

Thanks.

jackhab

Posted 2010-03-01T15:01:41.957

Reputation: 2 176

Answers

5

If you are using less as your man pager, you can set the environment variable to include a jump line number:

export LESS=-j4

for example (or add "j4" or a number you choose to the existing value of the variable). Here is mine:

export LESS=-iMFXRj4a

You can add or change that in your ~/.bashrc file so it's set each time you start a session.

Paused until further notice.

Posted 2010-03-01T15:01:41.957

Reputation: 86 075

1I needed to export the LESS variable before it worked. Example: export LESS=-j4 – gregh – 2011-06-27T20:48:00.960

@gregh: Thanks for the reminder. I added the export in my answer. – Paused until further notice. – 2011-06-28T02:05:02.253

3

Per default man uses the content of the environment variable $PAGER to display man pages (when it's not set, it uses /usr/bin/pager, which is usually a symbolic link to less).

See if you can find a text display program that has the behaviour you want (perhaps as an option) and put it in $PAGER.

Michael Borgwardt

Posted 2010-03-01T15:01:41.957

Reputation: 3 047

2

As suggested by Michael Borgwardt you can use a different "pager". For example I use vim for visualizing man pages by setting the following line in .bashrc:

export PAGER="/bin/sh -c \"col -b -x | view -c 'set ft=man nomodifiable' -c 'map q :q<CR>' -\""

In this way you will benefit from a more intelligent positioning of the highlighted search string and you will benefit from syntax highlighting (colored man pages).

If you still don't like how the searched string is placed you can give a cursor offset using:

/searchString/+[num]
/searchString/-[num]

mrucci

Posted 2010-03-01T15:01:41.957

Reputation: 8 398

The scrolloff option can also be useful for keeping context visible in Vim (around the cursor, not just after searches).

– Chris Johnsen – 2011-06-28T03:14:17.667

Immediately into my .vimrc! Thanks. – mrucci – 2011-06-28T16:06:02.483