I need to repeat a certain operation across several lines of code spread through out the code base. For instance,
x = y;
needs to be replaced with
EQUATE(x,y);
However each instance needs to be assessed manually, because say this needs to be done only when x
and y
have been declared as unit16_t
. So the functionality I seek is to be able to browse through various files of interest and anytime I come across a line where I feel the above operation needs to run, I should be able to just press a certain sequence of keys that would substitute the given line of code with the desired change. So say if I come across a line somewhere else that looks like below
struct_x.var_x = struct_y.var_y;
I should just be able to replace it with
EQUATE(struct_x.var_x, struct_y.var_y);
with a simple set of keystrokes.
:%s#\v\s*(.{-})\s*=\s*(.{-})\s*$#equate(\1, \2)#
NFA regexp Cant have a multi follow a multi
. Ended up using a macro instead as documented in the answer link.\v
it should be\=
instead of=