How to search using a template in VIM

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

Example:

I have an array and I want to find the indices of the array anywhere.

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

etc..

I'm looking for something in the lines

 /array*= 

if it is possible.

+6
source share
1 answer

I think you do not understand how the template works. It does not correspond to 0 or more characters, it corresponds to 0 or more from the previous atom, which in this case is equal to y . So the search

 /array*= 

will match any of them:

 arra= array= arrayyyyyyyy= 

If you want to match 0 or more characters, use a dot atom that matches any character other than a newline.

 /array.*= 

If you want something more reliable, I would recommend:

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

which is an "array" followed by 0 or more spaces, followed by everything in parentheses, followed by 0 or more spaces, and then the equal sign.

+10
source

Source: https://habr.com/ru/post/1013157/


All Articles