当前位置: 首页 > 工具软件 > TextTools > 使用案例 >

Sublime text 新建代码片段

司寇昱
2023-12-01

依次打开 Tools > Developer(开发者选项) > new Snippet(新的代码块)。可以看到官网已经给我们示例并 给出了具体提示:

<snippet>
	<content><![CDATA[
Hello, ${1:this} is a ${2:snippet}.
]]></content>
	<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
	<!-- <tabTrigger>hello</tabTrigger> -->  
	<!-- Optional: Set a scope to limit where the snippet will trigger -->
	<!-- <scope>source.python</scope> -->
</snippet>

然后在![CDATA[  ]]写上需要的代码段,${1: }写在需要光标暂停的位置,

下面写一个react代码段作为示例,并有中文注释:

<snippet>
	<content><![CDATA[
import React,{Component} from 'react';
export default class ${1: } extends Component{
	render(){
		return(
			)
	}
}
]]></content>
<!-- 可选:设置一个触发键来定义如何触发代码片段 -->
<tabTrigger>rrc</tabTrigger>
<!-- 设置一个范围来限制代码片段触发的位置 -->
<scope>source.js</scope>
</snippet>

 类似资料: