簡體   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