繁体   English   中英

如何在 VSCode 中为新文件设置“默认文本”

[英]How to set a "default text" to a new file in VSCode

有没有办法让 VSCode 将下面的代码添加到我创建的每个新文件中? 或者只有带有.cpp 扩展名的

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

这会让生活更轻松,因为我不需要每次创建新文件时都按 CTRL+C 和 V

恐怕没有扩展名是不可能的,尽管您可以编写一个片段来简化您的工作。

要创建或编辑您自己的片段,select 文件 > 首选项下的用户片段(macOS 上的代码 > 首选项),然后 select 语言。 在文件中写入以下内容并保存:

{
"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"
}

}

现在,在一些 *.cpp 文件中,开始写入“main”,VSCODE 将显示完整的单词。 只需点击选项卡,瞧。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM