Visual Studio Code介绍
Visual Studio Code是很轻量但功能强大的代码编辑器,可以在Windows、macOS和 Linux上运行。
User and Workspace Settings
通过settings,可以很容易地配置自己的Visual Studio Code。它提供了
two different scopes for settings:
- User Settings - Settings that apply globally to any instance of VS Code you open.
- Workspace Settings - Settings stored inside your workspace and only apply when the workspace is opened.
Workspace settings override user settings.
打开方式
页面打开:Code –> Preferences –> Settings,这种方式可以很直观地配置
也可以在json文件里直接修改:
- User Settings:
1 | ➜ User cat settings.json |
- Wrokspace: …
快捷键
默认常用快捷键
- (Command Palette | Show All Commands) shift + command + p 或者 F1
- 搜索文件 command + p
- 搜索内容(Find in Files) shift + command + f
- 回到上一个地方(Go Back) ctrl + -
- 跳到侧边栏(Focus into Side Bar) command + 0
- 切换侧边栏(Toggle Side Bar Visibility) command + b
- 打开原生的console(OpenNativeConsole) shift + command +c
- 切换Panel(Toggle Panel) command + j
- 调整Panel大小(Resize Panel) ctrl + command + <– | –>
Code navigation
![image](Visual-Studio-Code的使用总结/Code navigation.jpg)
- 跳转到定义(Go to Definition) F12
- (showAllSymbols) command + t
自定义快捷键
更改方式
打开键盘快捷键
Keyboard Shotcuts里显示当前支持哪些快捷键,包括默认的和自定义的;也可以在里面直接更改
Keyboard Shotcuts(json)里了自定义的快捷键;前面在Keyboard Shotcuts修改的会展示在这里,也可以在这里直接修改
常用自定义快捷键
根绝个人喜好,常用的如下:
1 | { |
常用插件
在左边Extensions里选择插件install。下面列出几种常用的插件:
Vim
遇到的问题
- Vim方向键无法长按
解决方案:终端下执行命令:
defaults write com.microsoft.VSCode ApplePressAndHoldEnabled -bool false
复原:
defaults write com.microsoft.VSCode ApplePressAndHoldEnabled -bool true
- 让 VIM yank 至剪切板的内容通过 ⌘ V 粘贴出来
配置如下 setting:
“vim.useSystemClipboard”: true,
Go
https://code.visualstudio.com/docs/languages/go
Auto completions
1 | "go.autocompleteUnimportedPackages": true, // Auto completions |
Code navigation
Code navigation features are available in the context menu in the editor.
- Go To Definition F12 - Go to the source code of the type definition.
- Peek Definition ⌥F12 - Bring up a Peek window with the type definition.
- Peek References ⇧F12 - Show all references for the type. (显示该类型的所有引用,个人觉得这个功能很强大)
You can navigate via symbol search using the Go to Symbol commands from the Command Palette (⇧⌘P).
Go to Symbol in File - ⇧⌘O
显示该文件的symbol,symbol: 指定义的函数,变量,类型等
Go to Symbol in Workspace - ⌘T
You can also navigate back and forth between a Go file and its test implementation using the Go: Toggle Test File command.
Debugging Go code using VS Code
设置一个或者多个GOPATH
C/C++
Edit Configurations
F1打开Command Palette –> C/C++: Edit configurations (JSON)
主要设置”includePath”, 便于代码跳转,参考 https://code.visualstudio.com/docs/cpp/c-cpp-properties-schema-reference
在终端里直接打开vscode
在vscode 中快捷键 shift + command + p 输入 code ,选择安装code 命令。
本质是做了个软链/usr/local/bin/code
用vscode打开当前目录:
1 | code . |