Q:

How to locate all occurences of search string

Using substitution, I want to replace
ones(var1.size,var2.size)

with
np.ones([var1.size,var2.size])

I tried using
%s/ones(\(\w\+\),\(\w\+\))/np.ones([\1,\2])/gc

based on other posts on Stack Overflow, however, Vim is unable to locate all occurrences of the search phrase.
It was able to locate ones(3,1) and change it to np.ones([3,1]), but it could NOT locate ones(1,xi.size).
Where am I going wrong?

A:

You're making it too hard. Here's how I figure out what Vim's going to do, and break it down into simpler steps:
/ones(\(.\+\))

will select the contents inside the parenthesis, then press Return so Vim remembers the pattern.
:%s//np.ones([\1])/

takes the remembered pattern and replaces it. Adjust your flags as necessary beforehand of course.
Simply match var1.size,var2.size.
Regular expressions are extremely powerful but can be maddening too, so keep them as simple as possible because the possibility of them doing the wrong thing goes up as complexity increases.

