1. VS Code Introduction
Visual Studio Code (简称VS Code) is 微软Development open-sourcecode编辑器, supportWindows, macOS and Linuxoperationsystem. 它具 has 轻量级, high performance, 丰富 插件生态 and 强 big functions, is 当 before 最受欢迎 code编辑器之一.
提示
VS Code and Visual Studio is 两个不同 产品. VS Code is 轻量级编辑器, 而Visual Studio is 完整 IDE (集成Developmentenvironment) , 主要用于.NETDevelopment.
2. VS Code under 载
您可以 from VS Code官方网站 under 载适合您operationsystem installationpackage:
- 官方 under 载地址: https://code.visualstudio.com/
- VS Code会automatically detect您 operationsystem, 并推荐相应 installationpackage
- 您也可以点击"Download for Windows/macOS/Linux"手动选择
2.1 Windows system
for 于Windowssystem, VS Codeproviding了两种installation选项:
- userinstallation程序 (User Installer) : 仅installation当 before user可用, 不需要management员permission
- systeminstallation程序 (System Installer) : installation所 has user可用, 需要management员permission
- 便携版 (Portable) : 解压即可using, 无需installation
2.2 macOS system
for 于macOSsystem, VS Codeproviding了两种installation选项:
- .dmg installationpackage: under 载 after 双击打开, 将VS Code拖动 to Applicationsfile夹
- Homebrew installation: usingHomebrewcommands行toolinstallation
2.3 Linux system
for 于Linuxsystem, VS Codeproviding了 many 种installation方式:
- .deb package: 适用于Debian/Ubuntusystem
- .rpm package: 适用于Red Hat/Fedorasystem
- Snap installation: 适用于supportSnap Linux发行版
- sources码installation: from GitHub under 载sources码编译installation
3. VS Code installation
3.1 Windows systeminstallation
- under 载适合您system installationpackage (推荐User Installer)
- 双击installationpackage, 启动installation向导
- 选择installation位置 (建议using默认位置)
- 选择附加task:
- creation桌面 fast 捷方式
- 添加 to PATH ( important , 方便 from commands行启动)
- register for support fileclass型 默认编辑器
- 添加 to on under 文菜单
- 点击"installation"按钮, etc.待installationcompletion
- installationcompletion after , 点击"completion"按钮启动VS Code
3.2 macOS systeminstallation
3.2.1 using .dmg installationpackage
- under 载 .dmg installationpackage
- 双击打开 .dmg file
- 将VS Codegraph标拖动 to Applicationsfile夹
- from Launchpad or Applicationsfile夹启动VS Code
3.2.2 using Homebrew installation
打开终端, 执行以 under commands:
brew install --cask visual-studio-code
3.3 Linux systeminstallation
3.3.1 Debian/Ubuntu system
under 载 .deb package after , 执行以 under commandsinstallation:
sudo dpkg -i code_*.deb
sudo apt install -f
3.3.2 Red Hat/Fedora system
under 载 .rpm package after , 执行以 under commandsinstallation:
sudo rpm -i code-*.rpm
3.3.3 using Snap installation
执行以 under commands:
sudo snap install --classic code
4. 首次启动 and basicconfiguration
首次启动VS Code时, 您会看 to 一个欢迎界面, package含以 under 选项:
- new 建file
- 打开file夹
- clonestorelibrary
- 最近 file
- UnderstandVS Code functions
4.1 选择language
VS Code默认using英文界面, 但您可以installationlanguagepackage切换 to in文:
- 按
Ctrl+Shift+P(Windows/Linux) orCmd+Shift+P(macOS) 打开commands面板 - 输入
configuration Display Language并选择 - 选择"Install additional languages..."
- in 搜索框in输入"Chinese", 找 to "Chinese (Simplified) Language Pack for VS Code"
- 点击"Install"按钮installationin文languagepackage
- installationcompletion after , 点击"Change Language and Restart"重启VS Code
4.2 basic设置
您可以through以 under 方式打开VS Code 设置界面:
- 按
Ctrl+,(Windows/Linux) orCmd+,(macOS) - 点击 left under 角 齿轮graph标, 选择"设置"
- in commands面板in输入
Preferences: Open Settings
常用 basic设置including:
- 主题 (Theme) : 选择喜欢 颜色主题 and graph标主题
- 字体 (Font) : 设置编辑器字体 and big small
- 自动保存 (Auto Save) : 选择自动保存file 时机
- Tab big small : 设置Tab键 indent空格数
- 行号 (Line Numbers) : 显示 or 隐藏行号
- 括号匹配 (Bracket Pair Colorization) : 启用括号颜色匹配
5. from commands行启动VS Code
such as果您 in installation时选择了"添加 to PATH", 则可以 from commands行启动VS Code:
5.1 启动VS Code
in 终端in执行以 under commands启动VS Code:
code
5.2 打开file or file夹
usingVS Code打开指定file or file夹:
# 打开当 before file夹
code .
# 打开指定file夹
code /path/to/folder
# 打开指定file
code /path/to/file.txt
# 打开 many 个file
code file1.txt file2.txt
6. commonissues and solution
6.1 无法 from commands行启动VS Code
issues: in 终端in执行 code commands时, 提示"command not found"
solution:
- check is 否 in installation时选择了"添加 to PATH"选项
- 重 new installationVS Code, 确保勾选"添加 to PATH"选项
- 手动将VS Code添加 to PATHenvironmentvariable
- in VS Codein, 按
Ctrl+Shift+P打开commands面板, 输入Shell Command: Install 'code' command in PATH并执行
6.2 VS Coderun缓 slow
issues: VS Code启动 or run时速度缓 slow
solution:
- 关闭不必要 插件
- 清除VS Codecache
- updateVS Code to 最 new version
- 增加VS Code可用 memory
6.3 in文显示乱码
issues: in VS Codein打开in文file时显示乱码
solution:
- 确保file编码 for UTF-8
- in VS Code right under 角点击编码格式, 选择"重 new 打开fileusing编码", 选择"UTF-8"
- in 设置in设置默认编码 for UTF-8
7. 练习
练习 1: installationVS Code
- from 官方网站 under 载适合您system VS Codeinstallationpackage
- 按照本tutorial 步骤installationVS Code
- 确保勾选"添加 to PATH"选项
- installationcompletion after , from 桌面 fast 捷方式启动VS Code
练习 2: configurationin文界面
- 启动VS Code
- installationin文languagepackage
- 将VS Code界面切换 for in文
- 重启VS Code, verification界面 is 否已切换 for in文
练习 3: from commands行启动VS Code
- 打开终端 or commands提示符
- 执行
codecommands, verificationVS Code is 否能 from commands行启动 - 执行
code .commands, verificationVS Code is 否能打开当 before file夹
练习 4: basic设置configuration
- 打开VS Code 设置界面
- 将编辑器字体 big small 设置 for 16
- 将Tab big small 设置 for 2
- 启用自动保存functions
- 选择一个喜欢 颜色主题