You are not logged in.
Hello,
I have been searching documentation about man and less (the default pager for manual pages) for a keystroke to jump directly to the next and previous section within a manpage. It would be such a useful navigation tool for huge pages such as man bash. Is there such a readymade keystroke/utility/hack?
Thanks
Last edited by a_neutrino (2010-07-01 05:10:52)
Offline
Well, if you use less as PAGER then you can set marks with m and revisit them with '
If you use vim then you can use { and } to skip paragraphs
Offline
I found it!
append this to /usr/share/groff/site-tmac/man.local :
.\" Add a searchable string before each section header
.rn SH SH-orig
.de SH
.SH-orig }} \\$*
..
Now there will be a }} prepended to every section header!!! You can put whatever you want instead.
explanation : man pages are parsed by groff. This file allows you to modify/add macros. I searched info groff to learn just enough to build this hack. Now I can do /}} in less to skip from one section to another!!!
.rn SH SH-orig #renames SH to SH-orig (SH is the section header macro)
.de SH #define SH
.SH-orig }} \\$* #make it like the original but prepend the text with "}} "
.. #the end (please note that these are not valid groff comments)
Offline
Strange, after I appended that to my man.local, this is all that's displayed for the manpage for cp:
() ()
}} NAME
()
~
~
~
~
In fact, I think that happens to each manpage parsed by groff with the strange exception of the man command itself! I assume your manpages work fine a_neutrino? Could you paste your man.local file so I can see if and how it differs from mine?
Offline
I assume your manpages work fine a_neutrino?
Yes, and the }} NAME part of your output is a good start. Don't forget that the last line of a macro declaration (.de) is marked by two dots (..).
Could you paste your man.local file so I can see if and how it differs from mine?
Yep :
.\" This file is loaded after an-old.tmac.
.\" Put any local modifications to an-old.tmac here.
.
.if n \{\
. \" Character translations for non-keyboard
. \" characters - to make them searchable
. if '\*[.T]'utf8' \{\
. char \- \N'45'
. char - \N'45'
. char ' \N'39'
. char \' \N'39'
. \}
.
. \" Shut off SGR by default (groff colors)
. \" Require GROFF_SGR envvar defined to turn it on
. if '\V[GROFF_SGR]'' \
. output x X tty: sgr 0
.\}
.
.\" Add a searchable string before each section header
.rn SH SH-orig
.de SH
.SH-orig }} \\$*
..
Offline
Yes, and the }} NAME part of your output is a good start. Don't forget that the last line of a macro declaration (.de) is marked by two dots (..).
Aha, I forgot the two dots at the end. I added them and the manpages work perfectly! Strange that groff doesn't mention any sort of syntax error though.
Thanks a_neutrino!
Offline
I wanted to offer my solution since I think it is quite a bit easier.
On my system, nearly all lines of a man page are displayed with leading whitespace. The only exception appears to be section headings. With that in mind, a simple regular expression search should do the trick:
/^\w
You may then type 'n' to jump to the next section or 'N' to jump to the previous one.
Offline
a simple regular expression search should do the trick:
/^\w
Cool! Thanks It's much more portable.
Allow me to add another point which applies to both solutions. less remembers the last search between invocations. The next time you consult a man page, pressing n will work directly without having to type the search command. You may use up and down arrows after pressing / to cycle the command history if you did a different search and want to come back to searching /^\w.
Offline