In the highly unlikely event that you haven't closed your vi session yet, open a new terminal and look for a .source-code.cpp.swp
file in the same folder. Remember that files starting with a period are not listed by ls
command by default; use ls -A
to see them.
The last line of the .swp
file would have the text from your original file before being corrupted by mal-compilation.
My original file test.cpp
#include <iostream>
using namespace std;
int main()
{
cout << "Hello World!" << endl;
cout << "Let us C";
}
The last part of my .test.cpp.swp
(in this case, it contained a single huge line).
@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@
@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@
@^@^@^cout << "Let us C";^@ cout << "Hello World!" << endl;^@{^@int main()^@^@using namespace std;^@#i nclude <iostream>^@
The .swp
file get deleted once you close the vi session; so if you've already closed it, you're out of luck.