推广 热搜: 还可  韩版  格式  氢气  制作工艺  避暑山庄  收购ACF  求购ACF  回收ACF  液压阀 

snippet 、snippets翻译

   日期:2023-04-20     浏览:37    评论:0    
核心提示:如何给sublime增加snippet1. Snippe创建,存储和格式 (这里snippet称作代码片段)Snippet可以存储在任何的文件夹中, 并且以.sublime-snippet为文件

如何给sublime增加snippet

1. Snippe创建,存储和格式

(这里snippet称作代码片段)

Snippet可以存储在任何的文件夹中, 并且以.sublime-snippet为文件扩展名, 默认是存储在.sublime-snippet文件夹下.

Snippet文件是以.sublime-snippet为扩展的XML文件, 可以命名为XXX.sublime-snippet, 创建自己的snippet的方式为菜单栏Tools | New Snippet..

下面看一下新建的文件格式:

snippet

content![CDATA[

Hello, ${1:this} is a ${2:snippet}.

]]/content

!-- Optional: Set a tabTrigger to define how to trigger the snippet --

!-- tabTriggerhello/tabTrigger --

!-- Optional: Set a scope to limit where the snippet will trigger --

!-- scopesource.python/scope --

/snippet

为了方便理解简化以上代码:

snippet

content![CDATA[Type your snippet here]]/content

!-- Optional: Tab trigger to activate the snippet --

tabTriggerhello/tabTrigger

!-- Optional: Scope the tab trigger will be active in --

scopesource.python/scope

!-- Optional: Description to show in the menu --

descriptionMy Fancy Snippet/description

/snippet

简要介绍一下snippet四个组成部分:

content:其中必须包含![CDATA[…]],否则无法工作, Type your snippet here用来写你自己的代码片段

tabTrigger:用来引发代码片段的字符或者字符串, 比如在以上例子上, 在编辑窗口输入hello然后按下tab就会在编辑器输出Type your snippet here这段代码片段

scope: 表示你的代码片段会在那种语言环境下激活, 比如上面代码定义了source.python, 意思是这段代码片段会在python语言环境下激活.

description :展示代码片段的描述, 如果不写的话, 默认使用代码片段的文件名作为描述

2. snippet环境变量

列举一下可能用到的环境变量, 这些环境变量是在Sublime中已经预定义的.

环境变量名 描述

$TM_FILENAME 用户文件名

$TM_FILEPATH 用户文件全路径

$TM_FULLNAME 用户的用户名

$TM_LINE_INDEX 插入多少列, 默认为0

$TM_LINE_NUMBER 一个snippet插入多少行

$TM_SOFT_TABS 如果设置translate_tabs_to_spaces : true 则为Yes

$TM_TAB_SIZE 每个Tab包含几个空格

同一通过下面的代码片段进行验证:

snippet

content![CDATA[

=================================

$TM_FILENAME 用户文件名

$TM_FILEPATH 用户文件全路径

$TM_FULLNAME 用户的用户名

$TM_LINE_INDEX 插入多少列, 默认为0

$TM_LINE_NUMBER 一个snippet插入多少行

$TM_SOFT_TABS 如果设置translate_tabs_to_spaces : true 则为Yes

$TM_TAB_SIZE 每个Tab包含几个空格

=================================

]]/content

!-- Optional: Set a tabTrigger to define how to trigger the snippet --

tabTriggerhello/tabTrigger

!-- Optional: Set a scope to limit where the snippet will trigger --

scopesource.python/scope

/snippet

验证方式 : 保存自定义snippet,在python文件夹下输入hello按下tab

3. snippet Fields

设置Fields, 可以通过tab键循环的改变代码片段的一些值

snippet

content![CDATA[

=================================

First Name: $1

Second Name: $2

Address: $3

=================================

]]/content

!-- Optional: Set a tabTrigger to define how to trigger the snippet --

tabTriggerhello/tabTrigger

!-- Optional: Set a scope to limit where the snippet will trigger --

scopesource.python/scope

/snippet

验证方式, 在python文件夹下, 输入hello按下tab, 会出现已经定义的代码片段, 不停的按下tab会发现输入光标在$1, $2, $3的位置跳转, 跳转顺序由数字由小到大决定, Shift+Tab可以进行向上跳转, 可以通过Esc结束跳转

4. snippet Mirrored Fields

设置snippet镜像区域,会使相同编号的位置同时进行编辑

snippet

content![CDATA[

=================================

First Name: $1

Second Name: $1

Address: $1

=================================

]]/content

!-- Optional: Set a tabTrigger to define how to trigger the snippet --

tabTriggerhello/tabTrigger

!-- Optional: Set a scope to limit where the snippet will trigger --

scopesource.python/scope

/snippet

验证方法: 在python文件中, 输入hello按下tab,出现代码片段,会出现三行同行编辑的光标, 这时进行编辑可以同时进行三行相同的编辑

5. snippet Placeholders

snippet 占位符含义类似于python的默认参数, 通过对Field做出一点修改, 可以定义Field的默认值, 并且可以通过tab键可以对不同的默认值进行修改

snippet

content![CDATA[

=================================

First Name: ${1:Guillermo}

Second Name: ${2:López}

Address: ${3:Main Street 1234}

User name: $1

Environment Variable : ${4:$TM_FILEPATH } #可以设置默认占位符为环境变量

Test: ${5:Nested ${6:Placeholder}}

=================================

]]/content

!-- Optional: Set a tabTrigger to define how to trigger the snippet --

tabTriggerhello/tabTrigger

!-- Optional: Set a scope to limit where the snippet will trigger --

scopesource.python/scope

/snippet

验证方式: 在pyton文件中输入hello,然后按下tab, 输入代码片段后, 两个$1的field可以同时修改默认值, 然后继续按下tab键可以修改$2的默认值..., 还可以占位符设置嵌套

写到这里基本上大家都应该可以根据需求编写简单的snippet了, 恭喜你..

6. snippet Substitutions

高级应用可以使用Perl的正则表达式

最后送上简单的python的snippet

snippet

content![CDATA[

"""

文档注释

Args :

${1}:

Returns :

${2}:

Raises :

${3}:

"""

]]/content

tabTrigger"""/tabTrigger

scopesource.python/scope

descriptiondocumentation Comments/description

/snippet

###

snippet

content![CDATA[def ${1:foo}():

doc = "${2:The $1 property.}"

def fget(self):

${3:return self._$1}

def fset(self, value):

${4:self._$1 = value}

def fdel(self):

${5:del self._$1}

return locals()

$1 = property(**$1())$0]]/content

tabTriggerproperty/tabTrigger

scopesource.python/scope

descriptionNew Property/description

/snippet

javascript nodejs snippets是什么作用

1、javascript是一直直译式脚本语言,相对Java来说是一种弱类型语言,他的作用是完成基于pc端和移动端浏览器所支持的所有动态功能,也就是交互功能

2、nodejs是封装了谷歌的v8引擎之后实现的一个javascript运行环境,他使用了一个事件驱动,非阻塞的I/O模型,轻量又高效,还是单线程的,擅长领域是后端的并发连接还有做响应速度快,易于扩展的网络应用

3、snippets是一款在Mac上使用的软件,是开发者用于保存源代码的工具

4、snippet是指为了解决在编写程序中需要反复利用某一部分代码而出现的一种方案,就是代码功能片段,主要体现在Sublime Text Snippet,将代码封装在snippet/snippet中,里面有个触发该片段的设置,当你想用这个片段的时候,输出触发的字母(比如自定义名称elem-edge),再按Tab键就出来了

snippet是什么意思中文?

Snippet n. 片段,小片,小部分

也可以指代码片段,是编程软件中的用词

关于snippet和snippets翻译的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。

原文链接:http://www.8178.org/news/show-40992.html,转载和复制请保留此链接。
以上就是关于snippet 、snippets翻译全部的内容,关注我们,带您了解更多相关内容。
 
标签: 片段 代码 按下
打赏
0相关评论

推荐资讯
网站首页  |  VIP套餐介绍  |  关于我们  |  联系方式  |  手机版  |  版权隐私  |  SITEMAPS  |  网站地图  |  排名推广  |  广告服务  |  积分换礼  |  网站留言  |  RSS订阅  |  违规举报