Visual Studio Code 生物信息学分析生信技巧

VSCode 添加代码模板

2019-04-24  本文已影响6人  JeremyL
VSCode Snippets

程序编写时,一段代码或说明会重复出现,使用模板有利于提高我们的工作效率。

VSCode 作为一种轻量级的代码编辑器,业界内颇受欢迎;下面就介绍一下如何利用VSCode snippet 制作代码模板。


# 创建一个snippets

Language selection

Snippets内容使用JSON格式进行定义。
一个JavaScript例子

{
    "For_Loop": {
        "prefix": "for",
        "body": [
          "for (const ${2:element} of ${1:array}) {",
          "\t$0",
          "}"
        ],
        "description": "For Loop"
    }
}

# Snippet语法

## Tabstops

$1$2指定代码块生成后,光标出现的位置;不同位置的相同$1位置同时出现光标。

## Placeholders

给光标出现位置加上默认值;例如,${1:another ${2:placeholder}}$1处位置默认值是another。

## Choice

光标位置设置多个值可供选择; 例如,${1|one,two,three|}$1位置处可以选择one,two,three中一个词填充在此处。

## Variables

${TM_FILENAME/(.*)\\..+$/$1/}
  |           |         |  |
  |           |         |  |-> no options
  |           |         |
  |           |         |-> references the contents of the first
  |           |             capture group
  |           |
  |           |-> regex to capture everything before
  |               the final `.suffix`
  |
  |-> resolves to the filename

# 一个python snippet

"python template": {
        "prefix": "pyHeader",
        "body": [
            "#!user/bin/python"
            "# _*_ coding: utf-8 _*_"
            " "
            "# @File    :   $TM_FILENAME"
            "# @Version :   1.0"
            "# @Author  :   xxxxxxx"
            "# @Email   :   xxxxxxx"
            "# @Time    :   $CURRENT_YEAR/$CURRENT_MONTH/$CURRENT_DATE $CURRENT_HOUR:$CURRENT_MINUTE:$CURRENT_SECOND"
            "#Description:"
            " " 

            "import datetime"
            "start_time = datetime.datetime.now()"

            "end_time = datetime.datetime.now()"
            "print(end_time-start_time)"
        ],
        "description": "my vue python template",
    }

# 参考:

Visual Studio Code Creating Snippets

上一篇 下一篇

猜你喜欢

热点阅读