LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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


Reply
  Search this Thread
Old 10-25-2005, 11:59 AM   #1
lordofring
Member
 
Registered: Feb 2005
Posts: 91

Rep: Reputation: 15
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.
 
Old 10-25-2005, 12:10 PM   #2
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
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 12:12 PM.
 
Old 10-25-2005, 12:55 PM   #3
deiussum
Member
 
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895

Rep: Reputation: 32
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.
 
Old 10-25-2005, 01:10 PM   #4
lordofring
Member
 
Registered: Feb 2005
Posts: 91

Original Poster
Rep: Reputation: 15
It's the exact what I want. Thanks, Jlightner

Dengyi
 
Old 10-25-2005, 01:47 PM   #5
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
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.
 
Old 10-25-2005, 03:11 PM   #6
deiussum
Member
 
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895

Rep: Reputation: 32
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.
 
Old 10-25-2005, 03:25 PM   #7
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
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 )
 
Old 11-16-2011, 08:11 AM   #8
space_ghost
LQ Newbie
 
Registered: Nov 2011
Posts: 1

Rep: Reputation: Disabled
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.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
having fstab-sync mount fat case-insensitive eliotstock Linux - General 9 06-05-2005 12:55 PM
Why are all my upper case files being shown as lower case?? [Kernel 2.6.9-1.667 FC3] t3gah Fedora 4 03-11-2005 04:09 PM
case insensitive search command ColKurtz Linux - Newbie 4 01-20-2005 07:02 AM
case-insensitive auto-complete gSalsero Programming 3 06-08-2004 07:33 AM
mySQL LIKE search is case sensitive? icepig Linux - Software 4 11-14-2003 04:29 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration