Visual Studio Code是个牛逼的编辑器,启动非常快,完全可以用来代替其他文本文件编辑工具。又可以用来做开发,支持各种语言,相比其他IDE,轻量级完全可配置还集成Git感觉非常的适合前端开发,是微软亲生的想必TypeScript会支持的非常好。 所以我仔细研究了一下文档未来可能会作为主力工具使用。

主命令框 Command Palette

最重要的功能就是F1Ctrl+Shift+P打开的命令面板了,在这个命令框里可以执行VSCode的任何一条命令,可以查看每条命令对应的快捷键,甚至可以关闭这个编辑器。

按一下Backspace会进入到Ctrl+P模式里

Ctrl+P 模式

Ctrl+P下输入>又可以回到主命令框 Ctrl+Shift+P模式。

Ctrl+P窗口下还可以

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

常用快捷键


编辑器与窗口管理

同时打开多个窗口(查看多个项目)

  • 打开一个新窗口: Ctrl+Shift+N
  • 关闭窗口: Ctrl+Shift+W

同时打开多个编辑器(查看多个文件)

  • 新建文件 Ctrl+N
  • 历史打开文件之间切换 Ctrl+TabAlt+LeftAlt+Right
  • 切出一个新的编辑器(最多3个)Ctrl+\,也可以按住Ctrl鼠标点击Explorer里的文件名
  • 左中右3个编辑器的快捷键Ctrl+1 Ctrl+2 Ctrl+3
  • 3个编辑器之间循环切换 Ctrl+`
  • 编辑器换位置,Ctrl+k然后按LeftRight

代码编辑

格式调整

  • 代码行缩进Ctrl+[, Ctrl+]
  • 折叠打开代码块 Ctrl+Shift+[, Ctrl+Shift+]
  • Ctrl+C Ctrl+V如果不选中,默认复制或剪切一整行
  • 代码格式化:Shift+Alt+F,或Ctrl+Shift+P后输入format code
  • 修剪空格Ctrl+Shift+X
  • 上下移动一行: Alt+Up 或 Alt+Down
  • 向上向下复制一行: Shift+Alt+UpShift+Alt+Down
  • 在当前行下边插入一行Ctrl+Enter
  • 在当前行上方插入一行Ctrl+Shift+Enter

光标相关

  • 移动到行首:Home
  • 移动到行尾:End
  • 移动到文件结尾:Ctrl+End
  • 移动到文件开头:Ctrl+Home
  • 移动到后半个括号 Ctrl+Shift+]
  • 选中当前行Ctrl+i
  • 选择从光标到行尾Shift+End
  • 选择从行首到光标处Shift+Home
  • 删除光标右侧的所有字Ctrl+Delete
  • Shrink/expand selection: Shift+Alt+LeftShift+Alt+Right
  • Multi-Cursor:可以连续选择多处,然后一起修改,Alt+Click添加cursor或者Ctrl+Alt+Down 或 Ctrl+Alt+Up
  • 同时选中所有匹配的Ctrl+Shift+L
  • Ctrl+D下一个匹配的也被选中(被我自定义成删除当前行了,见下边Ctrl+Shift+K)
  • 回退上一个光标操作Ctrl+U

重构代码

  • 跳转到定义处:F12
  • 定义处缩略图:只看一眼而不跳转过去Alt+F12
  • 列出所有的引用:Shift+F12
  • 同时修改本文件中所有匹配的:Ctrl+F12
  • 重命名:比如要修改一个方法名,可以选中后按F2,输入新的名字,回车,会发现所有的文件都修改过了。
  • 跳转到下一个Error或Warning:当有多个错误时可以按F8逐个跳转
  • 查看diff 在explorer里选择文件右键 Set file to compare,然后需要对比的文件上右键选择Compare with 'file_name_you_chose'.

查找替换

  • 查找 Ctrl+F
  • 查找替换 Ctrl+H
  • 整个文件夹中查找 Ctrl+Shift+F
    匹配符:
  • * to match one or more characters in a path segment
  • ? to match on one character in a path segment
  • ** to match any number of path segments ,including none
  • {} to group conditions (e.g. {**/*.html,**/*.txt} matches all html and txt files)
  • [] to declare a range of characters to match (e.g., example.[0-9] to match on example.0,example.1, …

显示相关

  • 全屏:F11
  • zoomIn/zoomOut:Ctrl + =/Ctrl + -
  • 侧边栏显/隐:Ctrl+B
  • 侧边栏4大功能显示:
    • Show Explorer Ctrl+Shift+E
    • Show SearchCtrl+Shift+F
    • Show GitCtrl+Shift+G
    • Show DebugCtrl+Shift+D
  • Show OutputCtrl+Shift+U
  • 预览markdownCtrl+Shift+V

其他

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

皮肤预览

f1后输入 theme 回车,然后上下键即可预览

自定义settings.json

User settings 是全局设置,任何vs Code打开的项目都会依此配置。

默认存储在:

Windows: %APPDATA%\Code\User\settings.json
Mac: $HOME/Library/Application Support/Code/User/settings.json
Linux: $HOME/.config/Code/User/settings.json

Workspace settings 是本工作区的设置,会覆盖上边的配置

存储在工作区的.vocode文件夹下。

几乎所有设定都在settings.json里,包括

  • Editor Configuration - font, word wrapping, tab size, line numbers, indentation, …
  • Window Configuration - restore folders, zoom level, …
  • Files Configuration - excluded file filters, default encoding, trim trailing whitespace, …
  • File Explorer Configuration - encoding, WORKING FILES behavior, …
  • HTTP Configuration - proxy settings
  • Search Configuration - file exclude filters
  • Git Configuration - disable Git integration, auto fetch behavior
  • Telemetry Configuration - disable telemetry reporting, crash reporting
  • HTML Configuration - HTML format configuration
  • CSS Configuration - CSS linting configuration
  • JavaScript Configuration - Language specific settings
  • JSON Configuration - Schemas associated with certain JSON files
  • Markdown Preview Configuration - Add a custom CSS to the Markdown preview
  • Less Configuration - Control linting for Less
  • Sass Configuration - Control linting for Sass
  • TypeScript Configuration - Language specific settings
  • PHP Configuration - PHP linter configuration

例如可以修改让vscode认识.glsl扩展名

{// Configure file associations to languages (e.g. "*.extension": "html"). These have precedence over the default associations of the languages installed."files.associations": {"*.glsl": "shaderlab"}
}

修改默认快捷键


File -> Preferences -> Keyboard Shortcuts

修改keybindings.json,我的显示在这里C:\Users\Administrator\AppData\Roaming\Code\User\keybindings.json

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// 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"
    }
]

自定义代码段


然后输入语言,例如我这里输入 typescript

由于每次输入箭头函数() => {}太烦了,我这里加入一段加入一段

1
2
3
4
5
6
7
"arrow function": {    "prefix": "func",
    "body": [
        "(${e}) => {$1}"
    ],
    "description": "arrow function"
}

保存后,下次输入func的时候就会自动出来箭头函数了

配置TypeScript环境


  1. 首先覆盖默认ctrl + space快捷键,因为这个快捷键被输入法切换占用了
    C:\Users\Administrator\AppData\Roaming\Code\User\keybindings.json
    加入

    1
    2
    3
    4
    5
    
    // Place your key bindings in this file to overwrite the defaults
    [
    { "key": "ctrl+alt+space",            "command": "editor.action.triggerSuggest",
                                         "when": "editorTextFocus" }
    ]
    
  2. File - Open Folder 打开项目的目录

  3. 创建 tsconfig.json
  4. 输入{} ,在大括号中间 ctrl + alt + space (上边的自定义键盘)

  1. 输入

    1
    2
    3
    4
    5
    6
    7
    
    {    "compilerOptions": {        "target": "ES5",
            "module": "amd",
            "sourceMap": true
        }
    }
    
  2. 可以创建.ts文件了

  3. 配置TaskRunner Ctrl+Shift+P 输入 Configure Task Runner
  4. Run Task Ctrl+Shift+B

安装typings

Install typings to bring in the .d.ts files which power javascript intellisense.

npm install typings --global# Search for definitions.
typings search tape# Find an available definition (by name).
typings search --name react# Install typings (DT is "ambient", make sure to enable the flag and persist the selection in `typings.json`).
typings install react --ambient --save

install will create a typings folder. VS Code will reference the .d.ts files for intellisense.

插件


新版本支持插件安装了

插件市场 https://marketplace.visualstudio.com/#VSCode

安装插件

F1 输入 extensions

点击第一个开始安装或升级,或者也可以 Ctrl+P 输入 ext install进入
点击第二个会列出已经安装的扩展,可以从中卸载

ext install

我在用的插件(期待更新…)

docthis 插件可以自动添加JSDoc注释。

ctrl + p 后 输入ext install docthis 可直接安装。

安装后连续两次 Ctrl+Alt+D 即可在光标处插入注释。

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

vscode-todo 显示todo列表

ctrl + p 后 输入ext install vscode-todo 可直接安装。

详细: https://marketplace.visualstudio.com/items?itemName=MattiasPernhult.vscode-todo

参考:

  • Learning Visual Studio Code
  • Key Bindings for Visual Studio Code
  • VS Code Tips and Tricks
from: https://nshen.net/article/2015-11-20/vscode/

学会用好 Visual Studio Code相关推荐

  1. Microsoft Visual Studio Code

    Microsoft Visual Studio Code 中文手册:https://www.cntofu.com/book/98/README.md Visual Studio Code 官网:htt ...

  2. 【实验手册】使用Visual Studio Code 开发.NET Core应用程序

    .NET Core with Visual Studio Code 目录 概述... 2 先决条件... 2 练习1: 安装和配置.NET Core以及Visual Studio Code 扩展... ...

  3. visual studio学习python_一步一步学Python3(小学生也适用) 第三篇: Visual Studio Code

    工欲善其事,必先利其器: 器欲尽其用,必先得其法. 前面两章我们分别安装了Python3.8和在三种模式下运行了Python的print()函数程序.在开始我们正式学习Python基础语法时,我们先把 ...

  4. VS Code (visual studio code) VSC 编辑器(微软出品,js开发的编辑器)

    一.选择合适的编辑器,提高编程效率 代码编辑器的选择,可以说是开发者社区中一个经久不衰的话题,现今编辑器的数量数不胜数,vim,sublime Text,Emacs,Atom等等,那么对于一个开发者而 ...

  5. 使用Visual Studio Code调试.net控制台应用程序的方法

    该文章的最新版本已迁移至个人博客[比特飞],单击链接:使用Visual Studio Code调试.net控制台应用程序的方法 | .Net中文网. 1.概述 本文向大家介绍使用Visual Stud ...

  6. 带你掌握Visual Studio Code的格式化程序

    摘要:Visual Studio Code 中的所有语言都可以使用其中一种自动格式化程序进行格式化,并且 Python 扩展还支持 linter. 本文分享自华为云社区<Visual Studi ...

  7. vscode wamp php,在WAMP环境中为Visual Studio Code安装PHP CodeSniffer(phpcs)

    导语:Visual Studio Code是微软发布的轻量级代码编辑器,它可以运行在Windows\Mac\Linux,通过扩展能够支持多种编程语言.PHP CodeSniffer是用来检查PHP编码 ...

  8. Visual Studio Code 如何编写运行 C、C++ 程序

    转载自https://www.zhihu.com/question/30315894/answer/154979413 侵删 作者:谭九鼎 链接:https://www.zhihu.com/quest ...

  9. 离线安装Visual Studio Code插件

    在使用Visual Studio Code 开发时候,有时可能会碰到需要离线安装插件的情况.这时候就需要单独下载插件包,本文就以C/C++插件包为例说明如何离线安装Visual Studio Code ...

最新文章

  1. RAPI简单说明及Sample Code
  2. echaer 地图_ECharts地图系列
  3. oracle DB死锁
  4. python-模块-pymysql操作数据库
  5. 基于VMware应用环境的备份恢复解决方案思路
  6. 重新理解创业:一个创业者的途中思考
  7. 双耳节拍 枕头_枕头2.2.1发布
  8. 计算机检索高考投档线,投档分数线是什么意思 低于投档线会被录取吗
  9. 16种常用的数据分析方法-列联分析
  10. 【Redis踩坑日记】Redis由于目标计算机积极拒绝,无法连接
  11. 六年级小学生做的个人网站
  12. 浅谈CPU 硬盘 内存关系
  13. pandas数据合并与重塑(pd.concat篇)
  14. C# 程序集(Assembly)
  15. 达内cgb2111第三次月考 76分就够了
  16. java Exception问题:unhandled exception:java.lang.Exception
  17. 响应式微服务_低风险整体式微服务演进第一部分
  18. K210学习笔记(五)——MAIX BIT(K210)与STM32串口通讯
  19. 听说虾皮、斗鱼要求校招生转 Go 了…
  20. 自考本计算机软件基础ppt,计算机软件基础自考本科

热门文章

  1. 你能活多少岁,就让人工智能来告诉你吧
  2. Java:按值传递还是按引用传递详细解说
  3. jvm性能调优实战 - 61常用的JVM调优网站
  4. Redis进阶 - 因异常断电导致的Redis Cluster Fail故障处理
  5. 高并发编程-happens-before
  6. Spring Cloud【Finchley】-03将微服务注册到Eureka Server上 + 为Eureka Server添加用户认证
  7. CoordinatorLayout+AppBarLayout实现上滑隐藏ToolBar-Android M新控件
  8. 学习笔记Hadoop(十五)—— MapReduce编程进阶
  9. 学习笔记(十八)——MongoDB(CRUD)与Python交互
  10. php上传图片限制类型,php,_使用php的图片上传类进行图片上传,总是提示:上传文件时出错 : 未允许类型 。都是默认的配置,php - phpStudy...