vs code使用技巧

vs code是微软推出的一款开源免费的代码编辑器,可运行在Windows,Linux,MacOS平台,官方下载地址如下:

https://code.visualstudio.com/

如果系统版本比较旧(如Ubuntu 16),安装新版本vs code可能会出现出现一些问题,可以在下面链接下载旧版本:

https://code.visualstudio.com/updates

1,安装插件

安装插件可以提高效率,可以参考我的安装:c/c++,python,DeviceTree,Makefile Tools,CMake。

2,快捷键

以Windows下为例:

  • Ctrl + 鼠标左键单击:跳转代码;
  • Alt + 左箭头:后退(返回跳转);
  • Alt + 右箭头:前进(进入跳转);
  • Alt + 上箭头:整行上移;
  • Alt + 下箭头:整行下移;
  • Alt + Shift + 上箭头:整行向上复制;
  • Alt + Shift + 下箭头:整行向下复制;
  • Shift + Del:剪切当前行(也可当作删除整行使用);
  • Ctrl + A && Ctrl + K && Ctrl + F:格式化全选代码;
  • Ctrl + K && Ctrl + T:切换主题;
  • Ctrl + P:搜索文件;
  • Ctrl + G:跳转到行;
  • Ctrl + F:文件内搜索/替换;
  • Ctrl + Shift + F:全局搜索关键字(折叠选项里可筛选搜索文件的范围,类型,及是否替换关键字);
  • 如果安装了c/c++这个插件,那么多行注释可以这样写: 先输入双引号内的字符"/***/",然后光标定位到倒数第一个"*"号之前,按下回车即可多行注释,范围内每一个回车自动新增注释一行;
  • 目录树栏有个OUTLINE(中文名叫大纲),可以查看函数目录;

3,内容定制

vs code面对大型代码工程时,在使用默认配置下,全局搜索和代码管理的效率非常低,我们需要调整配置,提高我们搜索和查看本地代码的效率,我们以Linux内核源码为例,在编译内核源码后,会产生大量的"*.o"的文件,这在全局搜索代码时,会拖慢我们找到代码的效率,除此之外,像"*.txt","*.md","*.rst"等文件,搜索时甚至大多数浏览代码时也不需要,我们就把它们屏蔽掉,下面是我针对全志一款芯片调整的Linux内核工程的vs code设置,首先在Linux内核根目录新建一个".vscode",(注意前面的逗点),在这个目录里新建两个json配置文件:c_cpp_properties.json和settings.json,分别写入如下内容:

c_cpp_properties.json

 1 {
 2     "configurations": [
 3         {
 4             "name": "Linux",
 5             "includePath": [
 6                 "${workspaceFolder}/**",
 7                 "${workspaceFolder}/include/**",
 8                 "${workspaceFolder}/arch/arm/include/**"
 9             ],
10             "intelliSenseMode": "linux-gcc-x64",
11             "compilerPath": "",
12             "cStandard": "c17",
13             "cppStandard": "c++17",
14             "configurationProvider": "ms-vscode.makefile-tools"
15         }
16     ],
17     "version": 4
18 }

settings.json

  1 {
  2     "search.exclude": {
  3         "**/node_modules": true,
  4         "**/bower_components": true,
  5         "**/*.o":true,
  6         "**/*.su":true,
  7         "**/*.cmd":true,
  8         "**/*.ko":true,
  9         "**/*.dtb":true,
 10         "**/*.log":true,
 11         "**/*.txt":true,
 12         "**/*.md":true,
 13         "**/*.rst":true,
 14         "**/*.git":true,
 15         "**/*.gitignore":true,
 16         "**/*.map":true,
 17         "**/*.py":true,
 18         "**/*.sh":true,
 19         "**/*.so":true,
 20         "**/*.a":true,
 21         "**/*.in":true,
 22         "**/*.scr":true,
 23         "Documentation":true,
 24         "LICENSES":true,
 25 
 26         /* 屏蔽不用的架构相关的文件 */
 27         "arch/alpha":true,
 28         "arch/arc":true,
 29         "arch/arm64":true,
 30         "arch/avr32":true,
 31         "arch/[b-z]*":true,
 32         "arch/arm/plat*":true,
 33         "arch/arm/mach-[a-r]*":true,
 34         "arch/arm/mach-[t-z]*":true,
 35         "arch/arm/mach-s3c*":true,
 36         "arch/arm/mach-s5p*":true,
 37         "arch/arm/mach-s[a-t]*":true,
 38 
 39         /* 屏蔽排除不用的配置文件 */
 40         "arch/arm/configs/[a-r]*":true, 
 41         "arch/arm/configs/[t-z]*":true,
 42         "arch/arm/configs/s3c*":true,
 43         "arch/arm/configs/s5p*":true,
 44         "arch/arm/configs/s[a-t]*":true,
 45 
 46         /* 屏蔽掉不用的DTB文件 */
 47         "arch/arm/boot/dts/[a-r]*":true,
 48         "arch/arm/boot/dts/[t-z]*":true,
 49         "arch/arm/boot/dts/s3c*":true,
 50         "arch/arm/boot/dts/s5pv*":true,
 51         "arch/arm/boot/dts/sam*":true,
 52         "arch/arm/boot/dts/sd*":true,
 53         "arch/arm/boot/dts/sh*":true,
 54         "arch/arm/boot/dts/soc*":true,
 55         "arch/arm/boot/dts/spear*":true,
 56         "arch/arm/boot/dts/st*":true,
 57         "arch/arm/boot/dts/*.tmp":true,
 58     },
 59     "files.exclude": {
 60         "**/.git": true,
 61         "**/.svn": true,
 62         "**/.hg": true,
 63         "**/CVS": true,
 64         "**/.DS_Store": true,
 65         "**/*.o":true,
 66         "**/*.su":true,
 67         "**/*.cmd":true,
 68         "**/*.ko":true,
 69         "**/*.dtb":true,
 70         "**/*.log":true,
 71         "**/*.txt":true,
 72         "**/*.md":true,
 73         "**/*.rst":true,
 74         "**/*.git":true,
 75         "**/*.gitignore":true,
 76         "**/*.map":true,
 77         "**/*.so":true,
 78         "**/*.a":true,
 79         "**/*.scr":true,
 80         "Documentation":true,
 81         "LICENSES":true,
 82 
 83         /* 屏蔽不用的架构相关的文件 */
 84         "arch/alpha":true,
 85         "arch/arc":true,
 86         "arch/arm64":true,
 87         "arch/avr32":true,
 88         "arch/[b-z]*":true,
 89         "arch/arm/plat*":true,
 90         "arch/arm/mach-[a-r]*":true,
 91         "arch/arm/mach-[t-z]*":true,
 92         "arch/arm/mach-s3c*":true,
 93         "arch/arm/mach-s5p*":true,
 94         "arch/arm/mach-s[a-t]*":true,
 95 
 96         /* 屏蔽排除不用的配置文件 */
 97         "arch/arm/configs/[a-r]*":true,
 98         "arch/arm/configs/[t-z]*":true,
 99         "arch/arm/configs/s3c*":true,
100         "arch/arm/configs/s5p*":true,
101         "arch/arm/configs/s[a-t]*":true,
102 
103         /* 屏蔽掉不用的DTB文件 */
104         "arch/arm/boot/dts/[a-r]*":true,
105         "arch/arm/boot/dts/[t-z]*":true,
106         "arch/arm/boot/dts/s3c*":true,
107         "arch/arm/boot/dts/s5pv*":true,
108         "arch/arm/boot/dts/sam*":true,
109         "arch/arm/boot/dts/sd*":true,
110         "arch/arm/boot/dts/sh*":true,
111         "arch/arm/boot/dts/soc*":true,
112         "arch/arm/boot/dts/spear*":true,
113         "arch/arm/boot/dts/st*":true,
114         "arch/arm/boot/dts/*.tmp":true,
115     }
116 }
settings.json

4,Web版VS Code

https://code.visualstudio.com/docs/editor/vscode-web

posted @ 2022-09-27 21:08  this毛豆  阅读(391)  评论(0编辑  收藏  举报