Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to search using wildcard in VIM

Using the standard search function (/) in VIM, is there a way to search using a wildcard (match 0 or more characters)?

Example:

I have an array and I want to find anywhere the array's indices are assigned.

array[0] = 1;
array[i] = 1;
array[index]=1;

etc.

I'm looking for something along the lines of

/array*=

if it's possible.

like image 233
Jimmy P Avatar asked Dec 14 '16 19:12

Jimmy P


1 Answers

I think you're misunderstanding how the wildcard works. It does not match 0 or more characters, it matches 0 or more of the preceding atom, which in this case is y. So searching

/array*=

will match any of these:

arra=
array=
arrayyyyyyyy=

If you want to match 0 or more of any character, use the 'dot' atom, which will match any character other than a newline.

/array.*=

If you want something more robust, I would recommend:

/array\s*\[[^\]]\+\]\s*=

which is "array" followed by 0 or more whitespace, followed by anything contained in brackets, followed by 0 or more whitespace, followed by an "equals" sign.

like image 113
DJMcMayhem Avatar answered Nov 16 '22 15:11

DJMcMayhem