VSCode 一字十行之代码片段

以前使用 Xcode 的字行之代时候,有一种方法可以把自己常用的码片「代码片段」保存起来,当在 Xcode 输入某个字符时即可提示你所保存的字行之代代码片段,可快速地完成编码。码片

今天查了下 VSCode,字行之代也有类似的码片功能,分享给大家。香港云服务器字行之代

比如我们创建一个 vue 组件的码片时候,通常会输入:

<template>   <div class="wrap">   </div> </template> <script lang="ts"> </script> <style lang="stylus" scoped> </style> 

我们习惯了粘贴复制,字行之代其实可以把这个代码定义成代码片段,码片以后输入一个字母既可以输入这些代码。字行之代

打开 VSCode,码片依次点击:

Code -> Preferences -> User Snippets -> New Global Snippets file,字行之代输入一个 snippet 文件名,码片我起名 vue,字行之代定义了两个代码片段:

(1) 打印输出

(2) vue 组件

{    "console": {      "scope": "javascript,typescript",     "prefix": "sy_log",     "body": [       "console.log($1);",       "$2"     ],     "description": "wsy to console"   },   "component": {      "scope": "",     "prefix": "sy_component",     "body": [       "<template>",           "    <div class=\"wrap\">",           "    </div>",         "</template>",         "",       "<script lang=\"ts\">",       "$3",         "</script>",         "",       "<style lang=\"stylus\" scoped>",       "$4",         "</style>"     ],     "description": "component of vue"   } } 

当在 VSCode 代码区域中输入 sy 的云服务器提供商时候会提示 sy_component 和 sy_log。

选择 sy_log ,按回车,输入的代码如下:

console.log(); 

选择 sy_component,按回车,输入的代码如下:

更多使用技巧,自己摸索一下即可!大家加油!

域名
上一篇:.com域名是国际最广泛流行的通用域名,目前全球注册量第一的域名,公司企业注册域名的首选。国际化公司通常会注册该类域名。
下一篇:④注册门槛低