I would like to know if it is possible for me to delete some lines/characters of a file in Vim, do some more work in that file, and then restore those lines/characters I originally deleted. I am asking this because I would like to temporarily remove some braces that are commented out in a C++ file. This is so that when locating the beginning and ending braces of a function/condition, Vim doesn't send me to one of the commented out braces. I know there are Vim plugins/add-ons that can fix this issue, but installing them is out of the question. And I should say that I definitely need to put back the braces.
So this is what I want to do. I have some code here that is only meant as an example and doesn't mean much in terms of functionality:
int mod(int a, int b) {
// if (true) {
// return a%b;
// }
return a%b;
}
So I want to first delete the commented out braces, and somehow save it:
int mod(int a, int b) {
// if (true)
// return a%b;
//
return a%b;
}
And then I'll make some modifications, maybe like this:
int mod(int a, int b) {
// if (true)
// return a%b;
//
if (b < 1) return -1;
else return a%b;
}
And then finally, I want to be able to restore those braces that I deleted before, using some combination of Vim commands:
int mod(int a, int b) {
// if (true) {
// return a%b;
// }
if (b < 1) return -1;
else return a%b;
}
Is this possible? I know worse comes to worst there are other more complicated ways of putting back those braces, but I am particularly curious if Vim has some way to do this. I should also mention that I am familiar with Vim, but I am by no means an expert.