最近经常使用markdown来写东西,但是使用的外挂标签打着又很麻烦所以在vscode上使用代码块来减少重复操作

设置代码块

在左上角 打开文件 --> 首选项 --> 用户代码片段

找到 markdown.json

  • “Print to console” 是快捷语句的标题
  • prefix 是快捷语句触发的命令,也就是关键字
  • body 是触发后的样子,使用 $1,$2 等指定光标位置。这些数字指定了光标跳转的顺序。特别地,$0表示最终光标位置
  • description 是该快捷语句的功能描述

image-20230424211637377

查看代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
"Print to md_del": {
"prefix": "del",
"body": [
"{% del $1 %}"
],
"description": "markdown删除样式"
},
"Print to md_kbd": {
"prefix": "kbd",
"body": [
"{% kbd $1 %}"
],
"description": "markdown键盘样式"
},
"Print to md_tabs": {

"prefix": "tabs",
"body": [
"{% tabs test4 %}",
"<!-- tab $1 -->",
" $0 ",
"<!-- endtab -->",
"{% endtabs %}"
],
"description": "markdown分栏"
},
"Print to ```java": {
"prefix": "```java",
"body": [
" ```java ",
"$0",
" ``` "
],
"description": "java代码"
},
"Print to ```python": {
"prefix": "```python",
"body": [
" ```python ",
"$0",
" ``` "
],
"description": "python代码"
},
"Print to ```shell": {
"prefix": "```shell",
"body": [
" ```shell ",
"$0",
" ``` "
],
"description": "shell终端"
},
"Print to md_danger": {
"prefix": "danger",
"body": [
" {% note danger modern %} $0 {% endnote %}",
],
"description": "红色警告框"
},
"Print to md_tips": {
"prefix": "tips",
"body": [
" {% note blue 'fas fa-bullhorn' modern %} $0 {% endnote %}",
],
"description": "蓝色喇叭提示框"
},
"Print to md_code": {
"prefix": "code",
"body": [
"{% folding green, 查看代码 %}",
"```",
" $0 ",
"```",
"{% endfolding %}"
],
"description": "折叠代码框"
},

启用设置

在设置setting.json中启用 打开 setting.json 添加

1
2
3
4
"[markdown]":{
"editor.quickSuggestions": true
}

image-20230424211916263

添加完后进行保存,然后就可以使用刚刚添加的快捷键了

vscode代码块