目 录CONTENT

文章目录

【VS Code】配置代码快捷提示

EulerBlind
2025-07-01 / 0 评论 / 0 点赞 / 1 阅读 / 0 字

配置路径

在这里插入图片描述 进入如下界面,如果需要特定语言的配置,则选择相应的语言,这里演示为全局配置,没有创建过全局snippets配置的,使用New Global Snippets file 选项进行配置 在这里插入图片描述 然后在如下配置界面输入需要该配置的名称 在这里插入图片描述

配置编辑

vs code的代码快捷键配置使用json格式来配置,对于新创建的文件会有如下提示,这里有一个默认的配置示例

{
  // Place your global snippets here. Each snippet is defined under a snippet name and has a scope, prefix, body and 
  // description. Add comma separated ids of the languages where the snippet is applicable in the scope field. If scope 
  // is left empty or omitted, the snippet gets applied to all languages. 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:
  // "Print to console": {
  //  "scope": "javascript,typescript",
  //  "prefix": "log",
  //  "body": [
  //    "console.log('$1');",
  //    "$2"
  //  ],
  //  "description": "Log output to console"
  // }
}

配置一个sql搜索快捷键

如果经常进行sql 操作,肯定避免不了要使用select * from 某个表,为了避免我们每次都要手k这么多单词,我们可以使用如下的template来实现。

{
  "select from table":{
    "scope": "sql",
    "prefix": "sf",
    "body":[
      "select * from $1 "
    ],
    "description": "select"
  }
}

配置解释

  1. 上述配置中,select from table 可以理解为该快捷操作的名称,自己随便定义
  2. scope 参数表示该文件生效的范围,后面为文件格式
  3. prefix 表示给定的快捷键,根据自己习惯进行编辑
  4. body 是一个列表,这里类似于jetbrains 的live Templates,其中有特殊变量 $1, $2 用于tab切换,$0表示终点位置,${1:label}, ${2:another} 表示带placeholders的变量位置
  5. description 为描述内容

配置后的效果

当我们在sql文件中键入 sf 后,会得到如下代码提示,选择应用,则可快捷应用到配置的模版 在这里插入图片描述

0

评论区