vim search multiple pattern with either this or that - search

I couldn't quite find help for this in forum w.r.t. vim search.
I'm looking to search for "abc.*(pqrs or xyz), that is I want abc with pqrs OR abc with xyz
/patternA.*(patternX|patternY)
I tried escaping "(" and "|", it didn't work. That is
/patternA.*(patternX\|patternY) also tried
/patternA.*(patternX\|patternY)
Thanks for your support.

/patternA.*\(patternX\|patternY\)

Related

How to replace one character with mutliple characters using search and replace in vim

In vim, I find myself searching for a character and in command mode doing x followed by 10p or 30p or something like that fairly often. I was wondering if there is a regular expression version that I could use in the :s/.../.../ command. \{m} work for matching m counts of of characters in the seach, but its equivalent s/X/X\{10}/gc replaces with the literal stringX{10}.
I've been searching the documentation and haven't found out how to do it yet, if anyone knows of a way I'd appreciate knowing about it.
You can use :h sub-replace-expression like this
%s/X/\=repeat(submatch(0), 10)/gc

(Gvim) How to delete a certain pattern which is embraced by certain characters

I like to delete all characters embraced by "[" and "]" including these embracing characters.
How can I do that?
Believe it or not, da[. Read :help text-objects to find out why, and what other kinds of regions you can use in this way (some other useful ones are aw for a word, and ap for a paragraph).
Perhaps use a find and replace like this:
:%s/\[.*\]//g

Vim Regex to replace tags

I am lookin for a regex express to remove the email addresses from a text file.
Input file:
Hannah Churchman <xxxx#xxxxxxxx.com>; Julie Drew <xxxx#xxxxxxxxx.com>;
Output file:
Hannah Churchman; Julie Drew;
I thought a generic regex shuch as s/<(.*?)>//g would be a good starting point but I am unable to find the right expression for use Vim?
something like
:%s/ <\(.*?\)>//g
does not work. Error is "E486: Pattern not found:".
:%s#[^ <]*>##g almost works but it leaves the space and < behind.
:%s# <##g to remove the " <" remaining stuff.
Any tips on how to better craft this command?
I tried this regex on your sample and it seems to work: :s/\s<[^\>]*>//g

vim does not find and replace simple phrase that is clearly present

I have a simple vim problem that Google hasn't managed to help me with. Any thoughts are appreciated.
I do the following search and replace:
:s/numnodes/numnodes1/g
On a file containing the following text:
numprocs=0
numnodes=0
I get
E486: Pattern not found
The position of the green square which indicates where I'd start typing is clearly above the pattern. I tried searching for other short phrases not involving regex, which are also present, which also fail. A simple /numnodes highlights matches as expected. Does anyone have any idea what might be the matter with vim?
Try :%s/searchphrase/replacephase/g
Without the % symbol Vim only matches and replaces on the current line.
try using this:
:%s/numnodes/numnodes1/g

Advanced searching in Vim

Is there a way to search for multiple strings simultaneously in Vim? I recall reading somewhere that it was possible but somehow forgot the technique.
So for example, I have a text file and I want to search for "foo" and "bar" simultaneously (not necessarily as a single string, can be in different lines altogether).
How do I achieve that?
/^joe.*fred.*bill/ : find joe AND fred AND Bill (Joe at start of line)
/fred\|joe : Search for FRED OR JOE
Actually I found the answer soon after I posted this (yes I did google earlier but was unable to locate it. Probably was just searching wrong)
The right solution is
/(foo\|bar)
#Paul Betts: The pipe has to be escaped
Vim supports regular expressions by starting in command mode with a '/'.
So using something like "/(foo\|bar)" (as was stated before) would solve the problem. It's good to know why that works and what you are using (regular expressions).
/(foo|bar)

Resources