vscode使用技巧

151 阅读1分钟

常用快捷键

通用快捷键

新建文件 ctrl + n 打开新窗口 ctrl + shift + n 打开项目所在文件夹 ctrl + o 保存当前文件 ctrl + s 关闭当前文件 ctrl + w 撤销操作 ctrl + z 取消撤销操作 ctrl + y 或 ctrl + shift + z 查找 ctrl + f 查找并替换 ctrl + h 放大缩小编辑器所有字体 ctrl + [+/-]

编辑操作

选择光标前相同内容 ctrl + d 选择当前行 alt + shift + 方向键右*2 复制 ctrl + c 粘贴 ctrl + v 复制当前行道上一行 alt + shift + 方向键上 复制当前行道下一行 alt + shift + 方向键下 格式化代码 alt + shift + f

更多快捷鍵:file > preferences > keyboard shortcuts

vscode 设置快速代码

例如:输入lg,按确定或者tab,生成console.log('');

设置路径:File > Preferences > User snippets > vue.json

{
    "vue2 template": {
        "prefix": "vue2",
        "body": [
            "<template>",
            "   <div></div>",
            "</template>",
            "",
            "<script>",
            "export default {",
            "   name: '',",
            "   data() {",
            "       return {};",
            "   },",
            "   methods: {},",
            "   computed: {},",
            "   created() {",
            "       // 实例创建完成,$el 属性尚未被挂载",
            "   },",
            "   mounted() {",
            "       // 实例挂载完成后调用",
            "   },",
            "   beforeDestroy() {",
            "       // 实例销毁之前调用",
            "   },",
            "   activated() {",
            "       // 当 keep-alive 组件激活时调用",
            "   },",
            "   deactivated() {",
            "       // 当 keep-alive 组件停用时调用",
            "   },",
            "};",
            "</script>",
            "",
            "<style scoped lang=\"scss\">",
            "</style>"
        ],
    },
    "Print to console": {
        "prefix": "lg",
        "body": [
            "console.log('$1');",
        ],
        "description": "Log output to console"
    }
}

User snippets 文件夾下的任意xx.json文件都可以用;简单介绍一下

"Print to console": { // 这个要取唯一,怎么命名都没问题
    "prefix": "lg", // 输入 xx (这里是lg),按tab或回车就能生成body中的内容
    "body": [
        "console.log('$1');", // 这里有 $0 $1 $2,经过测试是输入光标所在位置,权重是 1 > 2 > 0,和给的提示好像不同,都是用同一个就有多个地方可以同时输入
    ],
    "description": "Log output to console"
}