i want to do a like search in vi. e.g. i use the command
vi test.log
the file opens. now i want to do a forward search and i am looking for
[string1]%[string2] where % implies there can be any number of character in between these two strings (in a line). We have this kind of search in oracle(e.g. we often search for ‘pattern%’) . How to implement it in vi ?
i want to do a like search in vi. e.g. i use the command
Share
If there must be at least one character between the strings:
If there needn’t be any characters between the strings:
To use these, just start typing it; the leading
/will enter Vim’s search mode. Note that you may have to escape some of the characters instring1andstring2if they have special meaning in Vim’s regex syntax.Explanation:
.stands for any character (you can use\wif you just want to match “word” characters; i.e. letters, digits, and underscores).*means “0 or more instances of the preceding pattern”.\+means “1 or more instances of the preceding pattern”.Vim’s regex syntax is slightly different from the standard Perl regex syntax, which is why the
+quantifier needs a slash in front of it. Read more here: http://www.softpanorama.org/Editors/Vimorama/vim_regular_expressions.shtml