You are not logged in.

#1 2010-06-26 01:39:30

a_neutrino
Member
From: Montreal, Canada
Registered: 2010-03-14
Posts: 50
Website

[SOLVED] command to jump between sections in man page

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

#2 2010-06-26 01:56:46

andresp
Member
Registered: 2010-05-29
Posts: 62

Re: [SOLVED] command to jump between sections in man page

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

#3 2010-07-01 05:10:19

a_neutrino
Member
From: Montreal, Canada
Registered: 2010-03-14
Posts: 50
Website

Re: [SOLVED] command to jump between sections in man page

I found it! cool
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!!! big_smile 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

#4 2010-07-01 06:28:30

kcaze
Member
Registered: 2010-06-15
Posts: 5

Re: [SOLVED] command to jump between sections in man page

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

#5 2010-07-02 01:25:06

a_neutrino
Member
From: Montreal, Canada
Registered: 2010-03-14
Posts: 50
Website

Re: [SOLVED] command to jump between sections in man page

kcaze wrote:

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 (..).

kcaze wrote:

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

#6 2010-07-02 06:40:46

kcaze
Member
Registered: 2010-06-15
Posts: 5

Re: [SOLVED] command to jump between sections in man page

a_neutrino wrote:

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

#7 2010-11-02 04:45:47

battlepanic
Member
Registered: 2009-08-22
Posts: 75

Re: [SOLVED] command to jump between sections in man page

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

#8 2011-02-12 01:02:55

a_neutrino
Member
From: Montreal, Canada
Registered: 2010-03-14
Posts: 50
Website

Re: [SOLVED] command to jump between sections in man page

battlepanic wrote:

a simple regular expression search should do the trick:

/^\w

Cool! Thanks smile 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

Board footer

Powered by FluxBB