19

Trying to find out how to use case-insensitive searches in less I found this on serverfault.

That seems to perfectly answer my question. The problem is: It doesn't work like that here (openSUSE 13.1; less 458).

I had aliased less to less -WiNS but I changed that. But even calling it as command less file does not change anything. I have checked with ps that there is no -i option in the command line any more.

As the answer says the less help (pressing h) states that I can use -i within less, too. If I use that once then less tells me it had changed to case-insensitive search (that is kind of correct: nothing changes). If I use it twice then less tells me it had turned to case-sensitive search. And right, then it works as it should from the start. Giving -i twice on the command line does not work, though.

What's up here?

  • 1
    GNU less doesn't work like that for me (i.e., it is by default case sensitive). Are you sure it's not aliased? What options are you using with ps to check that? – goldilocks Feb 22 '14 at 14:05
  • 1
    Hmm. Never noticed this but you're absolutely correct. Searching for FOO finds just FOO, but searching for foo finds foo & FOO. Even with the -i and -WiNS. – slm Feb 22 '14 at 14:15
  • @goldilocks With ps I get either no (command less) options or -WNS so I am quite sure this is not a ps problem hiding -i/-I. less seems to have not even the possibility of a config file which could intervene here. – Hauke Laging Feb 22 '14 at 14:20
  • @slm "even with -i" is kind of funny because -i is supposed to do exactly that. The interesting question is: Does your less match FOO for foo without -i? – Hauke Laging Feb 22 '14 at 14:21
  • Nope it works the other way. FOO only matches FOO. Seems like a bug to me. – slm Feb 22 '14 at 14:24
23

I'm not sure how to enable this from the command line but when you're inside of less you can toggle the behavior you want by giving the -i command to less.

toggling -i

      ss #1        ss #2

searching for /blah and /BLAH

      ss #3       ss #4

searching for /Blah

      ss #5

Apparently you can also summon this mode on demand by suffixing your searches with a -i.

Example

less prompt> /search string/-i

References

  • That works for me, too, but I have to enter that twice. I guess I will write a bug report for openSUSE. – Hauke Laging Feb 22 '14 at 14:58
  • @HaukeLaging - It seems to stay as the default if you exit and come back in, can you confirm that behavior? – slm Feb 22 '14 at 14:58
  • No, but I have found out something interesting (not related to this "bug", though): You can use -i even after a search. The highlighting changes then (if it is active yet). – Hauke Laging Feb 22 '14 at 15:03
  • @HaukeLaging - ah yes that's it. So the notation is a bit squirrely compared to other tools. /search string/-i. – slm Feb 22 '14 at 15:06
5

The manual (for my less, version 444) says:

      Options are also taken from the environment variable "LESS".  For exam‐
   ple, to avoid typing "less -options ..." each time less is invoked, you
   might tell csh:

   setenv LESS "-options"

   or if you use sh:

   LESS="-options"; export LESS

   On  MS-DOS,  you don't need the quotes, but you should replace any per‐
   cent signs in the options string by double percent signs.

   The environment variable is parsed before the command line, so  command
   line  options  override  the  LESS  environment variable.
       On  MS-DOS,  you don't need the quotes, but you should replace any per‐
   cent signs in the options string by double percent signs.

   The environment variable is parsed before the command line, so  command
   line  options  override  the  LESS  environment variable.  If an option
   appears in the LESS variable, it can be reset to its default  value  on
   the command line by beginning the command line option with "-+".

So, I would check if the environment variable LESS might be set somewhere, in your shell "dot files" perhaps. Also, less -+i should reset the -i to its default (which is case-sensitive). If that brings back the case-sensitivity for you, then you could just alias less=less -+i, maybe together with alias lessi=less -i.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.