11

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?

goldilocks
  • 87,661
  • 30
  • 204
  • 262
  • 1
    The default is strict case sensitivity. What you described sounds like your LESS environment variable contains -i. – manatwork Apr 11 '14 at 13:45
  • 1
    What version of less do you have? Do you have an alias set for less? Is the LESS or LESSOPEN env vars set? By default a less search for x only matches x, not X – bsd Apr 11 '14 at 13:46
  • Didn't we already have this Q? I think Hauke asked it, I'll look for it....(slm comes back before the 5 mins. expires on the comment...) This one, not a dup but seems like what you're asking, no? http://unix.stackexchange.com/questions/116395/less-is-always-case-insensitive/116401#116401 – slm Apr 11 '14 at 14:15
  • @slm, this was my first reaction too, but as the question owner participated in that question, I suppose he knows about it. – manatwork Apr 11 '14 at 15:18
  • @manatwork echo $LESS = nothing. Note is it not case insensitve -- but it only enforces sensitivity WRT upper case. @bdowning alias | grep less = nothing. Just noticed it only applies via man (it's mandb, btw)., however. I'm sure I've read about this before somewhere... – goldilocks Apr 11 '14 at 15:58
  • @slm As per that answer toggling -i works. I'm going to change the question to refer to man specifically and add that as an answer (see previous comment). – goldilocks Apr 11 '14 at 16:02
  • @TAFKA'goldilocks' - thanks that's different now. – slm Apr 11 '14 at 16:07

3 Answers3

3

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

terdon
  • 242,166
1

This is how less's -i (command line switch) "case insensitive" mode works (i.e., it is still sensitive for upper case). As Gilles points out, using this is compiled into man-db.

In addition to the ways indicated in Gilles answer WRT setting an alias +-i or a custom MANLESS, you can toggle strict case matching once the man page opens up with -i (which turns the switch on and off); you will see a little "Case is significant in searches" message and now x only matches x and X only matches X.

Man-db's man has an -I switch, but this applies to the search for the man page -- e.g., by default man BASH will give you the bash manual page, whereas man -I BASH will not.

goldilocks
  • 87,661
  • 30
  • 204
  • 262
0

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

Here's one way

man -Tascii manpage |less

I don't know the gory details, but the roff processing is performing markup and the pager seems to be matching the un-marked up text, even though it is displaying the marked up text.
Very confusing, hopefully an nroff guru can explain the pipeline.

bsd
  • 11,036