当前位置: 首页 > 工具软件 > csc-manager > 使用案例 >

visual studio code 编辑器的配置及快捷键等, vscode, csc

齐冥夜
2023-12-01

visual studio code (vsc) 对开发node.js,javascript,python,html,golang等比较友好,同时支持git浏览及分屏对比,运行速度快,所以是值得一用的编辑器。

 

Visual Studio Code 最好的功能、插件和设置

Git Easy

这个插件可以导入下面的 Git 命令,以便您可以在命令面板中使用。和 Atom 中实用非常相似。

  • Git Easy: Init
  • Git Easy: Add Origin
  • Git Easy: Add Remote
  • Git Easy: Add File/Directory
  • Git Easy: Add All Modified
  • Git Easy: Commit
  • Git Easy: Pull Current Branch from Origin
  • Git Easy: Push Current Branch to Origin
  • Git Easy: Push Current Branch (to any remote)
  • Git Easy: Status
  • Git Easy: Create New Branch
  • Git Easy: Change/Checkout Existing Branch
  • Git Easy: Log All
  • Git Easy: Log Current File

https://marketplace.visualstudio.com/items?itemName=bibhasdn.git-easy

AutoFileName (文件路径自动补全插件)

当你需要 require 本地文件时,这个插件将为你提供基于你输入的文件路径的自动补全的选项。

https://marketplace.visualstudio.com/items?itemName=JerryHong.autofilename

ESLint

添加对 ESLint 的支持,并在安装和重启 VS Code 后自动开始工作。

https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint

JavaScript (ES6) Code Snippets (代码片段插件)

用代码片段加快 ES6 开发速度,例如输入 imd 可以自动生成如下代码:

JavaScript 代码:
  1. import { } from 'somewhere';

https://marketplace.visualstudio.com/items?itemName=xabikos.JavaScriptSnippets

Project Manager (项目管理器插件)

简单的项目管理器,可以在你的编辑器中快速切换项目。

https://marketplace.visualstudio.com/items?itemName=alefragnani.project-manager

Sort Lines (代码行排序插件)

这个插件可以对选中的代码行进行排序。也提供不区分大小写、反向和唯一等排序功能。

https://marketplace.visualstudio.com/items?itemName=Tyriar.sort-lines

Wallaby.js (测试插件)

一个高级的连续测试运行器,当您对您正在工作的文件进行测试时,它会在你的编辑器中创建通过测试或测试失败的视觉反馈。

https://marketplace.visualstudio.com/items?itemName=WallabyJs.wallaby-vscode

Sync Settings (设置同步插件)

你很有可能在多台电脑上进行编码工作。在电脑上移植你的插件和设置是轻而易举的事,这要归功于 Shan Ali Khan 的设置同步扩展。

https://marketplace.visualstudio.com/items?itemName=Shan.code-settings-sync

Git History (Git 历史记录插件)

可视化的 Git 历史记录插件。

https://marketplace.visualstudio.com/items?itemName=donjayamanne.githistory

EditorConfig (代码格式化插件)

添加对 EditorConfig 的支持,因此当您格式化文件时,它会引用此约定。

https://marketplace.visualstudio.com/items?itemName=EditorConfig.EditorConfig

Document This (JSDoc注释插件)

在 TypeScript 和 JavaScript 文件中自动生成详细的 JSDoc 注释。

https://marketplace.visualstudio.com/items?itemName=joelday.docthis

npm Intellisense (npm 模块导入插件)

VS Code 扩展,在 import 导入语句中自动完成npm 模块。

https://marketplace.visualstudio.com/items?itemName=christian-kohler.npm-intellisense

Align (代码对齐插件)

对齐文本,使代码根据 =:等对齐。

对齐前:

JavaScript 代码:
  1. var test = 'string';
  2. var another = 10;
  3. var small = 10 * 10;

对齐后:

JavaScript 代码:
  1. var test        = 'string';
  2. var another = 10;
  3. var small     = 10 * 10;

https://marketplace.visualstudio.com/items?itemName=steve8708.Align

amVim (vim 插件)

目前 VS Code 中的最好用的 vim 插件。不是下载最多的 vim 插件,但它使用的是多指针,不像那些下载最多的插件。

https://marketplace.visualstudio.com/items?itemName=auiworks.amvim

change-case (命名格式插件)

快速修改突出显示的选中文本的命名格式。 camelCase(骆驼拼命名),PascalCase(首字母大写),kebab-case(中划线命名),underscore_delimited(下划线命名),CONSTANT(大写命名)等。

https://marketplace.visualstudio.com/items?itemName=zhengxiaoyao0716.intelligence-change-case

vscode-icons (侧边栏图标插件)

可以更换侧边栏中漂亮的图标。

https://marketplace.visualstudio.com/items?itemName=robertohuertasm.vscode-icons

change-case (命名格式插件)

快速修改突出显示的选中文本的命名格式。 camelCase(骆驼拼命名),PascalCase(首字母大写),kebab-case(中划线命名),underscore_delimited(下划线命名),CONSTANT(大写命名)等。

https://marketplace.visualstudio.com/items?itemName=zhengxiaoyao0716.intelligence-change-case

 

在Visual Studio Code中配置GO开发环境

对于Visual Studio Code开发工具,有一款优秀的GoLang插件,它的主页为:https://github.com/microsoft/vscode-go

这款插件的特性包括:

  • Colorization 代码着彩色
  • Completion Lists 代码自动完成(使用gocode)
  • Snippets  代码片段
  • Quick Info 快速提示信息(使用godef)
  • Goto Definition 跳转到定义(使用godef)
  • Find References  搜索参考引用(使用go-find-references)
  • File outline 文件大纲(使用go-outline)
  • Workspace symbol search 工作区符号搜索(使用 go-symbols
  • Rename 重命名(使用gorename)
  • Build-on-save 保存构建(使用go build和go test)
  • Format 代码格式化(使用goreturns或goimports或gofmt)
  • Add Imports  添加引用(使用 gopkgs)
  • Debugging 调试代码(使用delve)

本插件的安装教程,请查看《Windows环境下vscode-go安装日记

Debugging Go code using VS Code

https://github.com/Microsoft/vscode-go/wiki/Debugging-Go-code-using-VS-Code

Install delve

If you are on Windows or Linux, running Go: Install/Update Tools would have installed delve for you. If you don't want to run that command or you are on OS X, you can manually install delve as per the Installation Instructions. On OS X it requires creating a self-signed cert to sign the dlv binary.

Based on how you install delve it will either end up in your PATH or GOPATH/bin. If dlv binary is in your GOPATH/bin and this GOPATH is not set as an environment variable, then make sure your PATH points to this GOPATH/bin so that the Go extension can find the dlv binary.

Set up configurations in launch.json

Once delve is installed, you can either press F5 or go to the Code debug viewlet and select the configuration gear.

You will now see a launch.json file created for your workspace, which will contain the configurations for debugging. By default, there would be a single configuration as below:

{
	"version": "0.2.0", "configurations": [ { "name": "Launch", "type": "go", "request": "launch", "mode": "debug", "remotePath": "", "port": 2345, "host": "127.0.0.1", "program": "${fileDirname}", "env": {}, "args": [], "showLog": true } ] }

Ignore remotePath, host and port if you are not remote debugging.

The program option is mandatory.

  • This can refer to a package folder to debug, or a file within that folder.
  • This should be a full path and not relative.
  • Use ${workspaceFolder} to debug package at the root of the workspace that is opened in VS Code
  • Use ${file} to debug the current file.

The mode parameter can be set to:

  • debug to compile the contents of the program folder and launch under the debugger. [default]
  • test to debug tests in the program folder. To debug a single test, pass -test.run and the Test name as args. Additionally, you can pass -test.v to get verbose output as well.
  • exec to run a pre-built binary specified in program, for example "program":"${workspaceRoot}/mybin".
  • remote to attach to a remote headless Delve server. You must manually run Delve on the remote machine, and provide the additional remotePath, host and port debug configuration options pointing at the remote machine.

In version 0.6.66 or lesser of the Go extension, the debugger cannot read your settings. It figures out the GOPATH from either the environment variables or from the path provided in the program option. If you have set multiple GOPATHs in the go.gopath setting, pass the same in the env option of the launch.json as an environment variable.

As of 0.6.67 version, the debugger will inherit the GOPATH from settings. Run Go: Current GOPATH command to see the GOPATH being used by the Go extension and the debugger.

Snippets for Debug Configurations

As of 0.6.54 version of the Go extension, you can now make use of snippets while editing the launch.json file. Type "Go" and you will get debug configuration snippets for debugging current file/package, a test function etc.

Debugging the Debugger?

Set showLog attribute in your debug configuration to true. You will see logs in the debug console from delve.

Set trace attribute in your debug configuration to verbose. You will see logs in the debug console from the Go extension's debug adapter. These logs will be saved to a file whose path will be printed at the beginning in the debug console.

If you want to dig deeper and debug the debugger using source code of this extension, read building-and-debugging-the-extension

Remote Debugging

To remote debug using VS Code, you must first run a headless Delve server on the target machine. For example:

$ dlv debug --headless --listen=:2345 --log

Any arguments that you want to pass to the program you are debugging must be passed to this Delve server that runs on the target machine. For example:

$ dlv debug --headless --listen=:2345 --log -- -myArg=123

Note: Do not pass the flag –api-version=2 to dlv. The Go extension doesn't support v2 of delve APIs yet.

Then, create a remote debug configuration in VS Code launch.json.

{
	"name": "Remote", "type": "go", "request": "launch", "mode": "remote", "remotePath": "${workspaceRoot}", "port": 2345, "host": "127.0.0.1", "program": "${workspaceRoot}", "env": {} }

When you launch the debugger with this new Remote target selected, VS Code will send debugging commands to the dlv server you started previously instead of launching it's own dlv instance against your app.

The above example runs both the headless dlv server and the VS Code debugger locally on the same machine. For an example of running these on different hosts, see the example of debugging a process running in a docker host at https://github.com/lukehoban/webapp-go/tree/debugging.

Troubleshooting

Cannot find Delve debugger at ... Ensure it is in your "GOPATH/bin" or "PATH".

Like the error message says, the extension cannot find dlv. Remember, the debug adapter cannot read the VS Code settings.

Solution: Add the location where dlv is installed to your PATH. You can find this location by running which dlv or where dlv

Cannot find package ".." in any of ...

The debugger is not using the right GOPATH. This shouldnt happen, if it does, log a bug.

Solution: Until the bug you logged is resolved, the work around is to add the GOPATH as an env var in the env property in the launch.json file.

Failed to continue: "Error: spawn EACCES"

You have dlv running just fine from command line, but VS Code gives this access related error. This can happen if the extension is trying to run the dlv binary from a wrong location. The Go extension first tries to find dlv in your $GOPATH/bin and then in your $PATH.

Solution: Run which dlv in the command line. If this doesnt match your GOPATH/bin, then delete the dlv file in your GOPATH/bin

could not launch process: stat ***/debug.test: no such file or directory

You may see this in the debug console, while trying to run in the test mode. This happens when the program attribute points to a folder with no test files.

Solution: Ensure that the program attribute points to the folder that contains the test files you want to run.

could not launch process: could not fork/exec

This usually happens in OSX due to signing issues. See the discussions in please see #717, #269 and derekparker/delve/357

Solution: You may have to uninstall dlv and install it manually as per instructions

could not launch process: exec: "lldb-server": executable file not found in $PATH

This error can show up for Mac users using delve of version 0.12.2 or above. Not sure why, but doing a xcode-select --install has solved the problem for users who have seen this issue.

Unverified breakpoints when remote debugging

Check the version of delve api being used in the remote delve process. v2 is not yet supported in the Go extension. So if you have –api-version=2 being passed to dlv, remove that flag and try again

 

 

 

vscode: Visual Studio Code 常用快捷键

主命令框

F1Ctrl+Shift+P: 打开命令面板。在打开的输入框内,可以输入任何命令,例如:

  • 按一下 Backspace 会进入到 Ctrl+P 模式
  • Ctrl+P 下输入 > 可以进入 Ctrl+Shift+P 模式

Ctrl+P 窗口下还可以:

  • 直接输入文件名,跳转到文件
  • ? 列出当前可执行的动作
  • ! 显示 ErrorsWarnings,也可以 Ctrl+Shift+M
  • : 跳转到行数,也可以 Ctrl+G 直接进入
  • @ 跳转到 symbol(搜索变量或者函数),也可以 Ctrl+Shift+O 直接进入
  • @ 根据分类跳转 symbol,查找属性或函数,也可以 Ctrl+Shift+O 后输入:进入
  • # 根据名字查找 symbol,也可以 Ctrl+T

常用快捷键

编辑器与窗口管理

  1. 打开一个新窗口: Ctrl+Shift+N
  2. 关闭窗口: Ctrl+Shift+W
  3. 同时打开多个编辑器(查看多个文件)
  4. 新建文件 Ctrl+N
  5. 文件之间切换 Ctrl+Tab
  6. 切出一个新的编辑器(最多 3 个) Ctrl+\,也可以按住 Ctrl 鼠标点击 Explorer 里的文件名
  7. 左中右 3 个编辑器的快捷键 Ctrl+1 Ctrl+2 Ctrl+3
  8. 3 个编辑器之间循环切换 Ctrl+
  9. 编辑器换位置, Ctrl+k然后按 LeftRight

代码编辑

格式调整

  1. 代码行缩进 Ctrl+[Ctrl+]
  2. Ctrl+CCtrl+V 复制或剪切当前行/当前选中内容
  3. 代码格式化: Shift+Alt+F,或 Ctrl+Shift+P 后输入 format code
  4. 上下移动一行: Alt+UpAlt+Down
  5. 向上向下复制一行: Shift+Alt+UpShift+Alt+Down
  6. 在当前行下边插入一行 Ctrl+Enter
  7. 在当前行上方插入一行 Ctrl+Shift+Enter

光标相关

visual studio code 快捷键:

0、回到上次光标的位置:

  On Windows:

    Alt+     .. navigate back

    Alt+     .. navigate forward

  On Mac:

    Ctrl+-     .. navigate back

    Ctrl+Shift+-     .. navigate forward

  On Ubuntu Linux:

    Ctrl+Alt+-       .. navigate back

    Ctrl+Shift+-       .. navigate forward

  1. 移动到行首: Home
  2. 移动到行尾: End
  3. 移动到文件结尾: Ctrl+End
  4. 移动到文件开头: Ctrl+Home
  5. 移动到定义处: F12
  6. 定义处缩略图:只看一眼而不跳转过去 Alt+F12
  7. 移动到后半个括号: Ctrl+Shift+]
  8. 选择从光标到行尾: Shift+End
  9. 选择从行首到光标处: Shift+Home
  10. 删除光标右侧的所有字: Ctrl+Delete
  11. 扩展/缩小选取范围: Shift+Alt+LeftShift+Alt+Right
  12. 多行编辑(列编辑):Alt+Shift+鼠标左键Ctrl+Alt+Down/Up
  13. 同时选中所有匹配: Ctrl+Shift+L
  14. Ctrl+D 下一个匹配的也被选中 (在 sublime 中是删除当前行,后面自定义快键键中,设置与 Ctrl+Shift+K 互换了)
  15. 回退上一个光标操作: Ctrl+U

重构代码

  1. 找到所有的引用: Shift+F12
  2. 同时修改本文件中所有匹配的: Ctrl+F12
  3. 重命名:比如要修改一个方法名,可以选中后按 F2,输入新的名字,回车,会发现所有的文件都修改了
  4. 跳转到下一个 ErrorWarning:当有多个错误时可以按 F8 逐个跳转
  5. 查看 diff: 在 explorer 里选择文件右键 Set file to compare,然后需要对比的文件上右键选择 Compare with file_name_you_chose

查找替换

  1. 查找 Ctrl+F
  2. 查找替换 Ctrl+H
  3. 整个文件夹中查找 Ctrl+Shift+F

显示相关

  1. 全屏:F11
  2. zoomIn/zoomOut:Ctrl +/-
  3. 侧边栏显/隐:Ctrl+B
  4. 显示资源管理器 Ctrl+Shift+E
  5. 显示搜索 Ctrl+Shift+F
  6. 显示 Git Ctrl+Shift+G
  7. 显示 Debug Ctrl+Shift+D
  8. 显示 Output Ctrl+Shift+U

其他

  • 自动保存:File -> AutoSave ,或者 Ctrl+Shift+P,输入 auto

修改默认快捷键

打开默认键盘快捷方式设置:
File -> Preferences -> Keyboard Shortcuts,或者:Alt+F -> p -> k

修改 keybindings.json

// Place your key bindings in this file to overwrite the defaults
[
    // ctrl+space 被切换输入法快捷键占用
    {
        "key": "ctrl+alt+space",
        "command": "editor.action.triggerSuggest",
        "when": "editorTextFocus"
    },
    // ctrl+d 删除一行
    {
        "key": "ctrl+d",
        "command": "editor.action.deleteLines",
        "when": "editorTextFocus"
    },
    // 与删除一行的快捷键互换
    {
        "key": "ctrl+shift+k",
        "command": "editor.action.addSelectionToNextFindMatch",
        "when": "editorFocus"
    },
    // ctrl+shift+/多行注释
    {
        "key":"ctrl+shift+/",
        "command": "editor.action.blockComment",
        "when": "editorTextFocus"
    },
    // 定制与 sublime 相同的大小写转换快捷键,需安装 TextTransform 插件
    {
        "key": "ctrl+k ctrl+u",
        "command": "uppercase",
        "when": "editorTextFocus"
    },
    {
        "key": "ctrl+k ctrl+l",
        "command": "lowercase",
        "when": "editorTextFocus"
    }
]

前端开发必备插件

  • PostCSS Sorting
  • stylelint
  • stylefmt
  • ESLint
  • javascript standard format
  • beautify
  • Babel ES6/ES7
  • Debugger for Chrome
  • Add jsdoc comments
  • javascript(ES6) code snippets
  • vue
  • weex
  • Reactjs code snippets
  • React Native Tools
  • Npm Intellisense
  • Instant Markdown
  • Markdown Shortcuts
  • TextTransform

自定义设置参考

vscode 自定义配置参考:

{
    "editor.fontSize": 18,
    "files.associations": {
        "*.es": "javascript",
        "*.es6": "javascript"
    },
    // 控制编辑器是否应呈现空白字符
    "editor.renderWhitespace": true,
    // 启用后,将在保存文件时剪裁尾随空格。
    "files.trimTrailingWhitespace": true,
    // File extensions that can be beautified as javascript or JSON.
    "beautify.JSfiles": [
        "",
        "es",
        "es6",
        "js",
        "json",
        "jsbeautifyrc",
        "jshintrc"
    ]
}

相关参考

官方快捷键大全:https://code.visualstudio.com/docs/customization/keybindings

 

转载于:https://www.cnblogs.com/welhzh/p/8757058.html

 类似资料: