VScode 代码片段示例
2026/11/27约 951 字大约 3 分钟
说明
- 该目录专门存放 Vscode 代码编辑器中的代码片段
- 可以用于初始化各语言文件的头注释、模板代码块等
- 配置路径:设置-->用户代码片段-->搜索目标语言的.json文件(python.json)
- 将对应文件内拷贝到 Vscode 内即可使用
C
{
// Place your snippets for c here. Each snippet is defined under a snippet name and has a prefix, body and
// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the
// same ids are connected.
// Example:
"初始化 c 文件": {
"prefix": "c",
"body": [
"${BLOCK_COMMENT_START}",
" * Author : wjiang",
" * E-mail : wjiang@cameyan.com",
" * Filename : ${TM_FILENAME}",
" * CreateTime : ${CURRENT_YEAR}-${CURRENT_MONTH}-${CURRENT_DATE} ${CURRENT_HOUR}:${CURRENT_MINUTE}:${CURRENT_SECOND} ${CURRENT_DAY_NAME}",
" * UUID : ${UUID}",
" * Function : $0",
" * Example",
" * - 1. ",
"${BLOCK_COMMENT_END}",
"",
"",
"#include <stdio.h>",
"",
"int main(int argc, char *argv[]) {",
" $1",
"",
" return 0;",
"}"
],
"description": "初始化 c 文件"
},
"添加 C 语言方法模板": {
"prefix": "c-func",
"body": [
"${BLOCK_COMMENT_START}",
" * author : wjiang",
" * e-mail : wjiang@cameyan.com",
" * createtime : ${CURRENT_YEAR}-${CURRENT_MONTH}-${CURRENT_DATE} ${CURRENT_HOUR}:${CURRENT_MINUTE}:${CURRENT_SECOND} ${CURRENT_DAY_NAME}",
" * function : ",
" * @parameter 1 : ",
" * @parameter 2 : ",
" * return : ",
"${BLOCK_COMMENT_END}",
"$0",
],
"description": "添加 C 语言方法模板"
}
}CSS
{
// Place your snippets for css here. Each snippet is defined under a snippet name and has a prefix, body and
// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the
// same ids are connected.
// Example:
"初始化 css 文件": {
"prefix": "css",
"body": [
"${BLOCK_COMMENT_START}",
" Author : wjiang",
" E-mail : wjiang@cameyan.com",
" Filename : ${TM_FILENAME}",
" CreateTime : ${CURRENT_YEAR}-${CURRENT_MONTH}-${CURRENT_DATE} ${CURRENT_HOUR}:${CURRENT_MINUTE}:${CURRENT_SECOND} ${CURRENT_DAY_NAME}",
" UUID : ${UUID}",
" Function : $0",
" Example",
" - 1. ",
"${BLOCK_COMMENT_END}",
"",
"",
],
"description": "初始化 css 文件"
}
}HTML
{
// Place your snippets for html here. Each snippet is defined under a snippet name and has a prefix, body and
// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the
// same ids are connected.
// Example:
"初始化 html 文件": {
"prefix": "html",
"body": [
"${BLOCK_COMMENT_START}",
" Author : wjiang",
" E-mail : wjiang@cameyan.com",
" Filename : ${TM_FILENAME}",
" CreateTime : ${CURRENT_YEAR}-${CURRENT_MONTH}-${CURRENT_DATE} ${CURRENT_HOUR}:${CURRENT_MINUTE}:${CURRENT_SECOND}",
" UUID : ${UUID}",
" Function : $0",
" Example",
" - 1. ",
"${BLOCK_COMMENT_END}",
"",
"",
"<!DOCTYPE html>",
"<html>",
" <head>",
" <meta charset=\"utf-8\">",
" <title>index</title>",
" </head>",
"",
" <body>",
"",
" $1",
"",
" </body>",
"</html>",
],
"description": "初始化 html 文件"
}
}JavaScripts
{
// Place your snippets for javascript here. Each snippet is defined under a snippet name and has a prefix, body and
// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the
// same ids are connected.
// Example:
"初始化 javascript 文件": {
"prefix": "js",
"body": [
"${BLOCK_COMMENT_START}",
" Author : wjiang",
" E-mail : wjiang@cameyan.com",
" Filename : ${TM_FILENAME}",
" CreateTime : ${CURRENT_YEAR}-${CURRENT_MONTH}-${CURRENT_DATE} ${CURRENT_HOUR}:${CURRENT_MINUTE}:${CURRENT_SECOND} ${CURRENT_DAY_NAME}",
" UUID : ${UUID}",
" Function : $0",
" Example",
" - 1. ",
"${BLOCK_COMMENT_END}",
"",
""
],
"description": "初始化 javascript 文件"
}
}Python3
{
// Place your snippets for python here. Each snippet is defined under a snippet name and has a prefix, body and
// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the
// same ids are connected.
// Example:
"初始化 python 文件":{
"prefix": "py",
"body": [
"#!/usr/bin/env python3",
"# -*- encoding: utf-8 -*-",
"",
"${BLOCK_COMMENT_START}",
" Author : wjiang",
" E-mail : wjiang@cameyan.com",
" Filename : ${TM_FILENAME}",
" CreateTime : ${CURRENT_YEAR}-${CURRENT_MONTH}-${CURRENT_DATE} ${CURRENT_HOUR}:${CURRENT_MINUTE}:${CURRENT_SECOND} ${CURRENT_DAY_NAME}",
" UUID : ${UUID}",
" Function : $0",
" Example",
" - 1. ",
"${BLOCK_COMMENT_END}",
"",
"",
],
"description": "初始化 python 文件"
}
}Shell
{
// Place your snippets for shellscript here. Each snippet is defined under a snippet name and has a prefix, body and
// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the
// same ids are connected.
// Example:
"初始化 shell 文件": {
"prefix": "shell",
"body": [
"#!/usr/bin/env bash",
"# ----------------------------------------------------------------------------",
"# Author : wjiang",
"# E-mail : wjiang@cameyan.com",
"# Filename : ${TM_FILENAME}",
"# CreateTime : ${CURRENT_YEAR}-${CURRENT_MONTH}-${CURRENT_DATE} ${CURRENT_HOUR}:${CURRENT_MINUTE}:${CURRENT_SECOND} ${CURRENT_DAY_NAME}",
"# UUID : ${UUID}",
"# Function : $0",
"# Example",
"# - 1. ",
"# ----------------------------------------------------------------------------",
"",
""
],
"description": "初始化 shell 文件"
}
}设置vscode目录不折叠
在 vscode 设置中搜索“Explorer: Compact Folders”选项,开启/关闭该选项
VS Code 插件推荐
| 插件 | 描述 | 链接 |
|---|---|---|
| Markdown Link Checker | 检查Markdown文件中图片链接有效性 | https://marketplace.visualstudio.com/items?itemName=dlyz.md-link-checker |
| Unused Images Finder | 检查本地或外部图床库中未使用图片 | https://marketplace.visualstudio.com/items?itemName=franciscoagustinr.ext-find-unused-imgs |