I'm not sure if the title makes sense, but I'll try to explain what I'm trying to do.
I have a file with some code like:
some_var = 3;
...
func(some_var);
The file has a bunch of calls to func
and I'd like to find all occurrences of the variable passed to each call. In this case I'd like to find some_var
on the line where it is assigned as well as where it is passed to the function. Unfortunately the variable name may differ in each instance, so I can't just search for the variable name directly.
Is there some way to search for the call to the function, capture the argument passed to it and then set the search pattern to that argument?
I tried the following, but it seems sub-expressions don't work with the :g
command:
:g/func(\(\w\+\))/let @/ = \1
/\v(\w+)\s*\=\s*\d+;\n(.*\n)*func\(\1\)
?func
and then find argument passed to the function.func
in given sample)... if\w
is not sufficient to cover all variable names, try\S
instead..