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
after:
// a line with old code
a line with new code
So far I did it manually: yy
+ p
to copy the line, :%s/\<old code\>/new code/gc
to replace with confirmation, then in the line I want to comment, esc
+ I
+ //
+ 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.
vim-fugitive
which allows me to cycle through all old versions of the file i have open inside my vim. With git you can lookup every step the file has taken and so on. But as I said, i am not the right guy for tips on version control, but there are surely enough articels about it