Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
10-25-2005, 12:59 PM
|
#1
|
Member
Registered: Feb 2005
Posts: 91
Rep:
|
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.
|
|
|
10-25-2005, 01:10 PM
|
#2
|
LQ Guru
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
|
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).
Last edited by MensaWater; 10-25-2005 at 01:12 PM.
|
|
|
10-25-2005, 01:55 PM
|
#3
|
Member
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895
Rep:
|
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.
|
|
|
|
10-25-2005, 02:10 PM
|
#4
|
Member
Registered: Feb 2005
Posts: 91
Original Poster
Rep:
|
It's the exact what I want. Thanks, Jlightner
Dengyi
|
|
|
10-25-2005, 02:47 PM
|
#5
|
LQ Guru
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
|
Glad I could help.
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. 
|
|
|
10-25-2005, 04:11 PM
|
#6
|
Member
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895
Rep:
|
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. 
|
|
|
10-25-2005, 04:25 PM
|
#7
|
LQ Guru
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
|
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  )
|
|
|
11-16-2011, 09:11 AM
|
#8
|
LQ Newbie
Registered: Nov 2011
Posts: 1
Rep: 
|
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]
|
|
1 members found this post helpful.
|
All times are GMT -5. The time now is 11:56 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|