1. advancedfunctionsoverview
VS Codeproviding了许 many advancedfunctions, 这些functions可以helping你更 high 效地forDevelopment. 本页面将介绍VS Code 一些coreadvancedfunctions, including:
- many 光标编辑
- commands面板advanced用法
- task and 构建system
- 远程Development
- containersDevelopment
- WSLDevelopment
- scaleDevelopment
- debugadvancedfunctions
- performanceoptimization
2. many 光标编辑
many 光标编辑 is VS Code 一项强 big functions, 允许你同时 in many 个位置for编辑.
2.1 basic many 光标operation
- 按住Alt键并点击鼠标: 添加 many 个光标
- Ctrl+Alt+Up/Down: in on 方/ under 方添加光标
- Ctrl+Shift+L: 选择所 has 匹配项并添加光标
- Ctrl+D: 选择 under 一个匹配项
- Ctrl+K+Ctrl+D: 跳过当 before 匹配项, 选择 under 一个
- Esc: 取消所 has many 光标
2.2 many 光标编辑case
// 原始code
const name1 = "Alice";
const name2 = "Bob";
const name3 = "Charlie";
// using many 光标编辑 fast 速modify
const name1 = { value: "Alice" };
const name2 = { value: "Bob" };
const name3 = { value: "Charlie" };
3. commands面板advanced用法
commands面板 is VS Code corefunctions之一, providing了访问几乎所 has VS Codefunctions 方式.
3.1 commands面板 fast 捷键
- Ctrl+Shift+P: 打开commands面板
- Ctrl+P: fast 速打开file
- Ctrl+Shift+O: in 当 before filein fast 速跳转符号
- Ctrl+T: in 所 has filein fast 速跳转符号
3.2 commands面板techniques
- in commands面板in输入"?"查看可用commands
- using"@" in 当 before filein跳转符号
- using"#" in 所 has filein搜索符号
- using">"执行commands
- using":"跳转 to 行号
4. task and 构建system
VS Code tasksystem允许你 in 编辑器inrun构建, test and othercommands.
4.1 creationtask
- 打开commands面板, run"task: configurationtask"commands
- 选择要creation taskclass型 (such asnpm, Gulp, Gruntetc.)
- VS Code会自动生成tasks.jsonconfigurationfile
4.2 tasks.jsonexample
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "npm",
"script": "build",
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": ["$tsc"]
},
{
"label": "test",
"type": "npm",
"script": "test",
"group": {
"kind": "test",
"isDefault": true
}
}
]
}
4.3 runtask
usingCtrl+Shift+Brun构建task, or throughcommands面板run"task: runtask"commands.
5. 远程Development
VS Code 远程Developmentscale允许你 in 远程server, containers or WSLinforDevelopment, 就像 in 本地Development一样.
5.1 远程Developmentscalepackage
installation"Remote Development"scalepackage, 它package含以 under 三个scale:
- Remote - SSH: throughSSH连接 to 远程server
- Remote - Containers: in DockercontainersinDevelopment
- Remote - WSL: in Windows Subsystem for LinuxinDevelopment
5.2 SSH远程Development
- installationRemote - SSHscale
- 点击 left under 角 绿色远程指示器
- 选择"Remote-SSH: Connect to Host..."
- 输入SSH连接information, such as
user@hostname - VS Code会 in 远程server on installation必要 component, 然 after 连接
5.3 containersDevelopment
usingRemote - Containersscale, 你可以 in DockercontainersinforDevelopment, 确保一致 Developmentenvironment.
6. scaleDevelopment
VS Code scaleAPI允许你creation自定义scale, scaleVS Code functions.
6.1 开始scaleDevelopment
- installationNode.js and npm
- installationYeoman and VS Codescale生成器:
npm install -g yo generator-code
- run生成器:
yo code
- 按照提示选择scaleclass型 and configuration
6.2 scaleprojectstructure
my-extension/ ├── src/ # sourcescode │ └── extension.ts # scale入口file ├── package.json # scaleconfiguration ├── tsconfig.json # TypeScriptconfiguration └── README.md # scale说明
6.3 debugscale
in VS Codein按F5可以启动scaledebugsession, VS Code会打开一个 new 窗口并加载你 scale.
7. debugadvancedfunctions
VS Code debugfunctionsproviding了许 many advanced features, helping你更 has 效地debugcode.
7.1 debugconfiguration
in launch.jsonin可以configuration complex debug场景, such as:
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch Program",
"type": "node",
"request": "launch",
"program": "${workspaceFolder}/app.js",
"args": ["--port", "3000"],
"env": {
"NODE_ENV": "development"
},
"sourceMaps": true,
"outFiles": ["${workspaceFolder}/dist/**/*.js"]
}
]
}
7.2 debug控制台advanced用法
- using
debugger;语句 in codein设置断点 - in debug控制台in执行JavaScript表达式
- usingwatch面板监视variable变化
- using调用栈面板查看function调用relationships
8. performanceoptimization
such as果VS Coderun缓 slow , 可以尝试以 under optimization措施:
8.1 scalemanagement
- 禁用不常用 scale
- 定期updatescale
- usingscalepackagemanagement相关scale
8.2 设置optimization
// optimization编辑器performance
"editor.largeFileOptimizations": true,
"editor.dragAndDrop": false,
"editor.quickSuggestions": {
"other": false,
"comments": false,
"strings": false
},
// optimization搜索performance
"search.followSymlinks": false,
"search.maxResults": 200,
// optimizationfilesystem监视
"files.watcherExclude": {
"**/.git/objects/**": true,
"**/.git/subtree-cache/**": true,
"**/node_modules/**": true,
"**/dist/**": true
}
8.3 硬件加速
确保启用了硬件加速:
"window.titleBarStyle": "custom", "disable-hardware-acceleration": false
9. 实践case: 远程DevelopmentNode.jsapplication
让我们through一个实践case来LearningVS Code 远程Developmentfunctions:
9.1 准备工作
- installationRemote - SSHscale
- 准备一台远程server, installationNode.js and Git
- configurationSSHkeyauthentication
9.2 连接 to 远程server
- 点击 left under 角 绿色远程指示器
- 选择"Remote-SSH: Connect to Host..."
- 输入SSH连接information, such as
user@remote-server - 连接成功 after , VS Code会显示远程server 名称
9.3 in 远程server on Development
- in 远程server on creation一个 new Table of Contents:
mkdir node-app - usingVS Code打开该Table of Contents
- 初始化Node.jsproject:
npm init -y - installationExpress:
npm install express - creationapp.jsfile:
- in VS Codein启动debug, 选择Node.jsenvironment
- in 本地浏览器in访问
http://remote-server-ip:3000
const express = require('express');
const app = express();
const port = 3000;
app.get('/', (req, res) => {
res.send('Hello from remote server!');
});
app.listen(port, () => {
console.log(`App listening at http://localhost:${port}`);
});
实践练习
请按照以 under 步骤completionadvancedfunctions练习:
- using many 光标编辑functions, 将以 under code转换 for arrayobject:
- creation一个 simple VS Codescale:
- usingYeoman生成器creation一个 new scale
- modifyscalecode, 添加一个 new commands
- debug并testscale
- configurationtasksystem:
- creation一个 simple JavaScriptproject
- configurationbuildtask and testtask
- usingCtrl+Shift+Brun构建task
- 尝试远程Development:
- installationRemote - SSHscale
- 连接 to 本地虚拟机 or 远程server
- in 远程server on creation并run一个 simple application
const item1 = "apple"; const item2 = "banana"; const item3 = "orange"; const item4 = "grape";
目标格式:
const items = [
{ name: "apple" },
{ name: "banana" },
{ name: "orange" },
{ name: "grape" }
];