Case insensitive search in man pages

7,993

Solution 1

When no other pager is specified, man uses less to display man pages.

The other answers that involve changing the pager command line are correct, but you can also type -i while less is running. From the less man page:

- Followed by one of the command line option letters (see OPTIONS below), this will change the setting of that option and print a message describing the new setting.

So typing -i while in less changes the setting in the same way that specifying it on the command line would. I got the hint that this would work from How do you do a case insensitive search using a pattern modifier using less, then found the explanation in the man page.

Solution 2

Only if you use caps, not if you just use lower case letters. For example, run man bash and try:

  • /invoc <== case insensitive
  • /Invoc <== case sensitive
  • /INVOC <== case sensitive

As @manatwork poited out in the comments, you can also control this behavior by adding export MANPAGER='less -I' to your ~/.profile. The MANPAGER variable defines which program is used with the man command. The -Imeans (from man less):

   -I or --IGNORE-CASE
          Like -i, but searches ignore case even if the  pattern  contains
          uppercase letters.

Other relevant options are (this one is usually on by default):

   -i or --ignore-case
          Causes searches to ignore case; that is, uppercase and lowercase
          are  considered identical.  This option is ignored if any upper‐
          case letters appear in the search pattern; in other words, if  a
          pattern  contains  uppercase  letters, then that search does not
          ignore case.

So, if you export MANPAGER="less -I"; man bash, you should be able to search for /iNvOc in a case-insensitive way.

Share:
7,993

Related videos on Youtube

FazJaxton
Author by

FazJaxton

Updated on September 18, 2022

Comments

  • FazJaxton
    FazJaxton over 1 year

    Is there a way to search man pages case-insensitively? Using the '/' search feature matches exact case.

  • Jeff Hewitt
    Jeff Hewitt over 10 years
    +1 Do you happen to know how one can force case sensitivity on an all-lowercase search pattern?
  • terdon
    terdon over 10 years
    @JosephR. man bash | grep -C 5 invoc but that's cheating.
  • Jeff Hewitt
    Jeff Hewitt over 10 years
    Yeah, not exactly the answer I was looking for. This may be worth another question on its own...
  • terdon
    terdon over 10 years
    @JosephR. apparently, you can compile less to use PCREs which might do the trick.
  • FazJaxton
    FazJaxton over 10 years
    The case-insensitive-for-lower-case only appears to be true if "-i" is specified on the command line. Without it, all searches are case sensitive.
  • WoodrowShigeru
    WoodrowShigeru almost 3 years
    @JosephR. It's the same switch – it's a toggle: type -i on man page. Feedback toggles between "Case is significant in searches" and "Ignore case in searches".