Search – Can I Force `man` to Do Lower Case Sensitive Matching?

case sensitivitylessmansearch

When I search man pages, the search is case sensitive, but only with regard to upper case letters. E.g., x will match x and X whereas X only matches x. This is the man-db version of man, used on fedora derived systems by default and available on others. man man says the default pager is less -s. $LESS is not defined in the environment, my $PAGER is just less, and I have no aliases for less.

This is not the behaviour when I invoke less on its own.

Is there anyway to force lowercase x to match only lowercasex when using man?

Best Answer

Man is calling Less; the only control at the man level is choosing which options to call Less with.

Less's search case-sensitivity is controlled by two options.

  • If -I is in effect, then searches are case-insensitive: either a or A can be used to match both a and A.
  • If -i is in effect but not -I, then searches are case-insensitive, but only if the pattern contains no uppercase letter.

If you make -I a default option for Less, then all searches will be case-insensitive even in man pages.

Man-db passes extra options to the pager via the LESS environment variable, which Less interprets in the same way as command line options. The setting is hard-coded at compile time and starts with -i. (The value is "-ix8RmPm%s$PM%s$" as of Man-db 2.6.2; the P…$ part is the prompt string.)

If you don't want searches in man pages to be case-sensitive, or if you want them to be always case-insensitive, there is no way to configure this in man-db itself. You can make an alias for man or a wrapper script that manipulates the LESS enviroment variable, as Man-db prepends its content to the current value if present:

alias man='LESS="$LESS -I" man'

To turn off the -i option and thus make searches always case-sensitive by default in man pages:

alias man='LESS="$LESS -+i" man'

You can also hard-code a different value for LESS by setting the MANLESS environment variable, but if you do that, then man just sets LESS to the value of MANLESS, you lose the custom title line (“Manual page foo(42)”) and other goodies (in particular, make sure to include -R for bold and underline formatting).

Related Question