I know there is one way to search and replace variable occurrences across a source file.
But is there any better way by which if I rename a variable at one place it gets renamed at other places as well without search and replace or substitute?
You can just use the usual workflow
/original cwreplaced n.n.
You can take also advantage of the
/original<CR> cgnreplaced<ESC> .....
next matched pattern, so instead of using
go to next and
repeat you can just
.. which means
gn means "search for next occurence and start a visual selection over it", you can read more about it on the doc:
You can use a substitute:
substitute across the entire file (
replaced. And will replace multiple occurrences on the same line
If you are not confident about automatically replacing, you can add the
c flag to ask for confirmation each time.
I'd like to add another option.
You can do
/original and then do
/c at the end if you want confirmation).
Although you are pressing 3 more keys, this has an advantage over doing just
%s/original/replacement because it provides a visual cue that your search is correct.