2

When I do man zshbuiltins I typically want to search for a command.

Suppose I'm looking for info on the alias command. I get a chunk of text like:

   : [ arg ... ]
          This  command  does nothing, although normal argument expansions
          is performed which may have effects on shell parameters.  A zero
          exit status is returned.

   alias [ {+|-}gmrsL ] [ name[=value] ... ]
          For  each  name with a corresponding value, define an alias with
          that value.  A trailing space in value causes the next  word  to
          be  checked  for  alias  expansion.   If the -g flag is present,
          define a global alias; global aliases are expanded even if  they
          do not occur in command position.

and I want to be able to jump right to the alias section of this horrible monolithic manpage.

I'm trying to search specifically for the case where it is the very first word on the line. However, all of the following expressions say "Pattern not found":

^alias
^\W*alias
^\s*alias
^[\W\s]*alias

How can I match alias if and only if it is the first word on the line? Or is there a better way to jump straight to a command? I think my default pager is Less (how can I check this?). Also I'm using Zsh in case that wasn't obvious.

5
  • 1
    It may just be prefixed with two spaces, so try searching for " alias" (or, spelled out: "<space><space>alias")
    – Jeff Schaller
    Jul 8, 2015 at 12:36
  • @JeffSchaller that did it and you should post it as an answer. Also I just realized that Less doesn't recognize shorthand character classes. ^[^[:alpha:]]+alias works just fine Jul 8, 2015 at 12:41
  • @ssdecontrol Have you considered enabling run-help?
    – fd0
    Jul 8, 2015 at 13:50
  • @fd0 I'm in the process of reconfiguring my system from scratch, so right now I don't have any quality of life features enabled. Jul 8, 2015 at 14:19
  • 2
    To jump directly to the right bit in the man page from the command line, see unix.stackexchange.com/questions/96095/… Jul 8, 2015 at 22:38

1 Answer 1

3

One option is to search with prefixed spaces, such as: / alias, where there are two spaces before the word "alias" to prevent false positive matches where "alias" appears as part of another sentence. You can also ground the match to the beginning of the line if you know exactly how many spaces there are: /^ alias for example.

However your expressions failed because Less search doesn't use shorthand character classes. ^[^[:alpha]]*alias should work (but two spaces is easier).

1
  • I missed your question towards the end about default pager; man looks in these places, in this order: (1) -P flag; (2) MANPAGER; (3) PAGER; (4) if none of the above are set, it uses less. (All from man man).
    – Jeff Schaller
    Jul 8, 2015 at 13:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .