How to set a "default text" to a new file in VSCode

Viewed 684

Is there any way to make VSCode add this code below to every new file i create? or only the ones with .cpp extension

#include <iostream>
#include <iomanip>
#include <math.h>
 
using namespace std;
 
int main() {
 
    return 0;
}

this would make life easier as i wouldn't need to CTRL+C and V every time i create a new file

1 Answers

I'm afraid it isn't possible without an extension, although you can write an snippet to make your work easy.

To create or edit your own snippets, select User Snippets under File > Preferences (Code > Preferences on macOS), and then select the language. Write the following in the file and save it:

{
"Default file": {
    "prefix": "main",
    "body": ["#include <iostream>", "#include <iomanip>", "#include <math.h>", "\nusing namespace std;", "\nint main() {", "\nreturn 0;", "\n}"],
    "description": "My default cpp file"
}

}

Now, in some *.cpp file, start write "main" and VSCODE will show you the complete word. Just hit tab and voila.

Related