5

When I open a man page, for example man chmod and I hit / for searching a string in the page I can see all the matching strings highlighted.

Pressing n or N will focus on the next/previous matching string.

Is there a way to highlight the current match (the one with the focus) differently from all the matching strings?

5

This is controlled via MANPAGER.

Manual pages defaults to the pager of less -is.

You can just highlight the current selection:

man -P "less -isg" <command>

Or set the MANPAGER variable:

export MANPAGER="less -isg"

You could also use vim where the cursor is highlighted so the current selection will appear differently.:

 man -P "sh -c \"col -b | vim -c 'set ft=man ts=8 nomod nolist nonu' \
    -c 'nnoremap i <nop>' \
    -c 'nnoremap <Space> <C-f>' \
    -c 'noremap q :quit<CR>' -\"" <command>

Taken from Zameer Manji:

  1. ft=man enables the coloring of the man page.
  2. ts=8 ensures the width of tab characters matches less.
  3. nomod removes the modification warning when trying to quit.
  4. nonu removes line numbers.
  5. nolist disables listchars so trailing whitespace and extra tabs are not highlighted.
  6. nnoremap i ensures that we do not accidentally enter insert mode when viewing the man page.

Plus my own option to use space to paginate and quit with q:

-c 'nnoremap <Space> <C-f>'
-c 'noremap q :quit<CR>'

Set it as your default pager by adding it to your default profile:

export MANPAGER="sh -c \"col -b | vim -c 'set ft=man ts=8 nomod nolist nonu' \
    -c 'nnoremap i <nop>' \
    -c 'nnoremap <Space> <C-f>' \
    -c 'noremap q :quit<CR>' -\""
  • thanks, "less -isg" will highlight the current match but not all the others. Is there a way to highlight it differently? Also is PAGER a global variable to export at shell startup? – Leonardo Oct 28 '14 at 10:45
  • 1
    Yes export MANPAGER= can be added to your shell profile. I have added another option to use vim instead which will give you a different current selection. – geedoubleya Oct 28 '14 at 11:07
  • Thanks again, any way to reach the same result using the less version? – Leonardo Oct 28 '14 at 13:47
  • There is a way to use pygments to highlight the pages in less, although I have not tried combining this with man. – geedoubleya Oct 28 '14 at 14:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.