VS Code快捷键与操作
-
重命名类名、变量名
选中类名、变量名 点击F2
进行更改 -
转到变量名的定义处
F12
-
同时选择上一行
Ctrl + Alt + Up
或者下一行Ctrl + Alt + Down)
的相同位置 -
找出文中所有的当前选中的单词
Ctrl + D
-
选中文中所有的当前选中的单词
Ctrl + Shift + L
-
删除整行快捷键
Ctrl + Shift + K
-
选中光标所在当前行
Ctrl + L
-
光标在下一行的最前可以直接复制内容到当前行的上一行
-
改变注释颜色
在settings.json中加入以下代码://改变注释颜色 "editor.tokenColorCustomizations": { "comments": "#ff4f81" // 注释 }
-
改变选中与高亮颜色
在settings.json中加入以下代码://修改选中与高亮颜色 "workbench.colorCustomizations": { "editor.selectionBackground": "#000000", "editor.selectionHighlightBackground": "#c5293e" }
-
格式化代码
Shift+Ctrl+F
设置Ctrl+S 自动格式化
添加以下代码:
"editor.formatOnType": true, "editor.formatOnSave": true,
保存settings.json。
-
同时添加多个光标
单个添加: 将光标放在一个位置,然后按住Alt键的时候用鼠标点击其他地方,点到的地方就会添加一个光标出来
添加一整列: 按住Shift+Alt然后鼠标下拉,即可添加一整列光标
错误
- js拼错定义的类名
怎么解决?
忘掉的语法
<link type="text/css" rel="styleSheet" href="CSS文件路径" />
<style type="text/css"> @import url("css文件路径"); </style>
插件
- js doc
/**
写注释Ctrl+Shift+D
- JavaScript Snippets
JS代码片段补全 - JavaScript (ES6) code snippets
ES6的代码片段
解决问题
- 怎么截会动的截图
- 总是输错JS类名(HTML、JS的联动)
- 修改注释字体
解决的问题
- CSDN代码块底色修改方法
博客管理-博客设置
JS缩写快速输入
-
Console相关语法
[cd]
console.dirconsole.dir(${1:obj});
[ce]
console.errorconsole.error(${1:obj});
[ci]
console.infoconsole.info(${1:obj});
[cl]
console.logconsole.log(${1:obj});
[cw]
console.warnconsole.warn(${1:obj});
[de]
debuggerdebugger;
-
DOM相关语法
[ae]
addEventListener${1:document}.addEventListener('${2:event}', function(e) { ${0:// body...} });
[ac]
appendChild${1:document}.appendChild(${2:elem});
[rc]
removeChild${1:document}.removeChild(${2:elem});
[cel]
createElement${1:document}.createElement(${2:elem});
[cdf]
createDocumentFragment${1:document}.createDocumentFragment();
[ca]
classList.add${1:document}.classList.add('${2:class}');
[ct]
classList.toggle${1:document}.classList.toggle('${2:class}');
[cr]
classList.remove${1:document}.classList.remove('${2:class}');
[gi]
getElementById${1:document}.getElementById('${2:id}');
[gc]
getElementsByClassName${1:document}.getElementsByClassName('${2:class}');
[gt]
getElementsByTagName${1:document}.getElementsByTagName('${2:tag}');
[ga]
getAttribute${1:document}.getAttribute('${2:attr}');
[sa]
setAttribute${1:document}.setAttribute('${2:attr}', ${3:value});
[ra]
removeAttribute${1:document}.removeAttribute('${2:attr}');
[ih]
innerHTML${1:document}.innerHTML = '${2:elem}';
[tc]
textContent${1:document}.textContent = '${2:content}';
[qs]
querySelector${1:document}.querySelector('${2:selector}');
[qsa]
querySelectorAll${1:document}.querySelectorAll('${2:selector}');
-
Loop相关语法
[fe]
forEach${1:myArray}.forEach(function(${2:elem}) { ${0:// body...} });
[fi]
for infor (${1:prop} in ${2:obj}) { if (${2:obj}.hasOwnProperty(${1:prop})) { ${0:// body...} } }
-
Function相关语法
[fn]
functionfunction ${1:methodName} (${2:arguments}) { ${0:// body...} }
[afn]
anonymous functionfunction(${1:arguments}) { ${0:// body...} }
[pr]
prototype${1:ClassName}.prototype.${2:methodName} = function(${3:arguments}) { ${0:// body...} }
[iife]
immediately-invoked function expression(function(${1:window}, ${2:document}) { ${0:// body...} })(${1:window}, ${2:document});
[call]
function call${1:methodName}.call(${2:context}, ${3:arguments})
[apply]
function apply${1:methodName}.apply(${2:context}, [${3:arguments}])
[ofn]
function as a property of an object${1:functionName}: function(${2:arguments}) { ${3:// body...} }
-
JSON相关语法
[jp]
JSON.parseJSON.parse(${1:obj});
[js]
JSON.stringifyJSON.stringify(${1:obj});
-
Timer相关语法
[si]
setIntervalsetInterval(function() { ${0:// body...} }, ${1:delay});
[st]
setTimeoutsetTimeout(function() { ${0:// body...} }, ${1:delay});
-
NodeJS相关语法
[ase]
assert.equalassert.equal(${1:actual}, ${2:expected});
[asd]
assert.deepEqualassert.deepEqual(${1:actual}, ${2:expected});
[asn]
assert.notEqualassert.notEqual(${1:actual}, ${2:expected});
[me]
module.exportsmodule.exports = ${1:name};
[pe]
process.exitprocess.exit(${1:code});
[re]
requirerequire('${1:module}');
-
BDD相关语法
[desc]
describedescribe('${1:description}', function() { ${0:// body...} });
[ita]
it asynchronousit('${1:description}', function(done) { ${0:// body...} });
[its]
it synchronousit('${1:description}', function() { ${0:// body...} });
[itp]
it pendingit('${1:description}');
- Misc相关语法
[us]
use strict'use strict';
[al]
alertalert('${1:msg}');
[co]
confirmconfirm('${1:msg}');
[pm]
promptprompt('${1:msg}');