visual-studio-code - 在 Visual Studio Code 中创建文件时自动添加代码片段
问题描述
有没有办法在基于文件类型/扩展名创建文件时将代码片段添加到文件中。我想在创建新的 C++ 头文件时添加头保护。例子:
#ifndef DIRECTORY_FILENAME_H
#define DIRECTORY_FILENAME_H
#endif // DIRECTORY_FILENAME_H
我已经创建了一个添加此文本的代码片段,但我不知道如何在创建文件时自动添加它。
解决方案
https://marketplace.visualstudio.com/items?itemName=Gruntfuggly.auto-snippet
例子:
autoSnippet.snippets: [
{ "pattern": "ut-*.cpp", "snippet": "ut-template",
{ "pattern": "*.h", "snippet": "header-template" },
{ "pattern": "*.cpp", "snippet": "body-template",
{ "language": "javascript", "snippet": "template", "commands":"[ editor.action.commentLine" ] }
]
推荐阅读
- c++ - 哈希表 - 析构函数问题(未分配被释放的指针)
- git - Git subtree pull 删除我的顶级存储库中的文件
- python - 加入线程内的主线程
- sql-server - 将 varchar 值“01-4001”转换为数据类型 int 时转换失败
- swift - 为什么不通过将同名的预先存在的属性与所需的类型保持一致来暗示一致性?
- json - 使用 jq 从多个文件中匹配和合并
- flutter - 是否可以从 json 主体中打印多个属性?
- xml - 使用 XSLT 循环遍历嵌套节点,而不指定属性
- css - 在样式化组件中使用 `css` 函数会导致性能下降吗?
- robocopy - 在“仅报告”模式下运行 Robocopy