vscode php snippet,VScode添加自定义代码段snippet

snippet 简介

snippet即代码段,指的是能够帮助输入重复代码模式,比如循环或条件语句的模板。通过 snippet ,我们仅仅输入一小段字符串,就可以在代码段引擎的帮助下,生成预定义的模板代码,接着我们还可以通过在预定义的光标位置之间跳转,来快速补全模板。

vsCode进入snippet的三种方法

1.通过快捷键「Ctrl + Shift + P」打开命令窗口(All Command Window),输入「snippet」,点选「首选项:配置用户代码段片段」;

47a7c52865c7?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

47a7c52865c7?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

2.点击界面最左侧竖栏(也即活动栏)最下方的齿轮按钮,在弹出来的菜单中点选「用户代码片段」

47a7c52865c7?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

3.按下「Alt」键切换菜单栏,通过文件 > 首选项 > 用户代码片段;

47a7c52865c7?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

例子简介

在以上的输入框中输入vue,找到 vue.json ,然后在 vue.json 里面配置。以下是一个vue的例子

{

// Place your snippets for vue 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:

// "Print to console": {

// "prefix": "log",

// "body": [

// "console.log('$1');",

// "$2"

// ],

// "description": "Log output to console"

// }

}

prefix:前缀,定义了 snippets 从 IntelliSense 中呼出的关键字

body: 主体,即模板的主体内容,其中每个字符串表示一行

description:说明,会在 IntelliSense 候选栏中出现。未定义的情况下直接显示对象名。

把上面的设置更改为自己想要的样子

{ // 把example 的注释去掉

"Print to console": {// 这个代码段的名字,随便起

"prefix": "log",// 绑定的关键字

"body": [// 输入 Log 时,生成的内容,每行内容包含在双引号里,用逗号间隔

"console.log('$1');",//$1 光标出现的位置,如果不设置,默认出现在末尾

"$2"//用tab,切换到下一个参数位置

],

"description": "Log output to console"//对这个代码段的简单描述

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值