如何在VSCode中创建每个工作区片段?

时间:2017-06-01 16:12:27

标签: json visual-studio-code

我想添加一些项目特定的代码段。

如何在.vscode文件夹中添加摘要?

4 个答案:

答案 0 :(得分:5)

enter image description here

这有帮助吗?它来自最新的VSCode release (1.28.1)

答案 1 :(得分:2)

据我所知,这在VS Code中根本无法直接实现。阅读完VS代码文档后:https://code.visualstudio.com/docs/editor/userdefinedsnippets< - 我发现没有提到这一点。

度过愉快的一天。

答案 2 :(得分:1)

转到File -> Prefrences -> User snippets。 选择New Snippets for ${project name}。 为代码段文件选择一个名称。 阅读刚刚创建的文件中的注释,然后复制示例以创建第一个片段。

答案 3 :(得分:0)

this solution on vscode issues in github,您只需要:

  1. 创建扩展名为schema = {'names': ['Field1', 'Field2', 'Field3'], 'type': ['STRING', 'STRING', 'INTEGER']} data = [] for n,t in zip(schema['names'], schema['type']): data.append({'name': n, 'type': t}) 的文件(例如.code-snippets),并
  2. 将要记住的内容添加到该文件中。例如typescript.code-snippets的简单fog代码段:
console.log
  1. 将该文件放入工作区的{ "Print to console": { "prefix": "fog", "body": [ "console.log('$1');", "$2" ], "description": "Log output to console" } } 文件夹中(但不在其子文件夹中)。

在VS Code 1.36.1上,它就像一个魅力。