LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   how to search in VI wih case insensitive (https://www.linuxquestions.org/questions/programming-9/how-to-search-in-vi-wih-case-insensitive-376770/)

lordofring 10-25-2005 11:59 AM

how to search in VI wih case insensitive
 
Hi guys,

I'm wondering how to do a case in-sensitive search in vi. I'm looking for a switch. Something like -i switch for grep. For example
Code:

grep "string" file -i
.

By the way, :set ignorecase and :set smartcase are not what I'm looking for.

MensaWater 10-25-2005 12:10 PM

Could you elaborate? the :set ignorecase is exactly how you do it in vi. Are you saying it doesn't work? Are you trying to do a command line option?
Is it perhaps that you don't understand the usage. You do the ":set ignorecase" then hit enter THEN do the search - you're not trying to do it all on one line are you?

Or maybe you're trying to figure out how to turn it on so you don't have to bother typing the :set each time? If so:
Type "echo set ignorecase" >>.exrc" in your home directory.
The .exrc is read each time you start vi.



Of course its possible you have some flavor of vi that doesn't understand ed set commands but I haven't yet run across one (but then again I immediately install vim wherever I see nvi).

deiussum 10-25-2005 12:55 PM

I found this in the vim user manual pages (chapter 27.1) for you. Sounds like what you might want.

Quote:

CASE IN ONE PATTERN

If you want to ignore case for one specific pattern, you can do this by
prepending the "\c" string. Using "\C" will make the pattern to match case.
This overrules the 'ignorecase' and 'smartcase' options, when "\c" or "\C" is
used their value doesn't matter.

pattern matches ~
\Cword word
\CWord Word
\cword word, Word, WORD, WoRd, etc.
\cWord word, Word, WORD, WoRd, etc.

A big advantage of using "\c" and "\C" is that it sticks with the pattern.
Thus if you repeat a pattern from the search history, the same will happen, no
matter if 'ignorecase' or 'smartcase' was changed.

lordofring 10-25-2005 01:10 PM

It's the exact what I want. Thanks, Jlightner

Dengyi

MensaWater 10-25-2005 01:47 PM

Glad I could help.

Quote:

chapter 27.1
That's why NO ONE knows all there is to know about vi. Imagine having to memorize 27 or more chapters just to get all the options for one command. :study:

deiussum 10-25-2005 03:11 PM

Heheh, yeah, there is a lot there. I'm sure emacs has just as much, though. In this case, I found it simply by typing :help regexp, and then following some links in the help. (By moving the cursor over the links and hitting ctrl-])

Anyway, you don't really need to memorize everything vim can do. Once you pick up a few key features you can get along with it pretty well. But if there is ever something you want to find a way to do quicker in vim, there are probably more things you don't know about that you can search the help for. :)

MensaWater 10-25-2005 03:25 PM

Yes I know. Been using vi since 1991 - vim has a few more features but vi (not nvi which bites) has a similarly long man page. I was just noting this is why no one actually memorizes it.

I am NOT a fan of emacs. In fact when developers ask me to install emacs for them I tell 'em to go pound sand (or do "man vi" which they somehow take the same way :rolleyes: )

space_ghost 11-16-2011 08:11 AM

how to search in VI wih case insensitive
 
or how to search in VIM with ignoring case sensitive

to search for non-case sensitive words, once you are in vim file, type:

:set ic

then,

/[your search]


All times are GMT -5. The time now is 07:36 PM.