Libraries evolve all the time and I often face the situation where after an update some function name have changed and they return errors in the updated version of the library.
It's easy to replace all the instances of a word by another however I would like to keep track of the old version by commenting the line containing the old function name, as follows:
original line (which raises an error)
a line with old code
// a line with old code a line with new code
So far I did it manually:
p to copy the line,
:%s/\<old code\>/new code/gc to replace with confirmation, then in the line I want to comment,
esc and I use the repeat command
. to add my comment to the other appropriate lines. This is fine for few dozen lines of code but not for hundreds of lines, so I'd like to make this less manual.
The steps to be taken would be:
- search lines with the old code (old function name)
- copy the lines
- comment the original lines: add
//(or other) in front of the line
- replace the old code in the uncommented line
Can this be done in a "vim-apprentice" friendly manner? More advanced methods will be welcome too.