0.总结
- 换编辑器总是痛苦的事情,但是适应了就也觉得还好
- pycharm 转 vscode的辛酸记
- 持续更新~
安装
下载完 vscode 之后该怎么做呢?先装一下 python 这个插件,才可以编译运行python程序。
1.快捷键
-
ctrl+shift+space
查看方法的参数列表 -
配置常用的命令
选择python文件,进行编辑,如下所示:
那么就尅在编辑窗口直接使用
log
就可以自动打出console.log($1)
了。 -
ctrl+shift+\
可以在匹配的括号间进行快速匹配
2.debug配置
2.1 基本文件
调试是程序很重要的一个步骤,vscode调试程序的时候,需要使用 launch.json
这个文件,这个文件放在.vscode
文件夹下。如下所示:
- 红框1表示的是项目名
- 红框2表示的是配置信息
2.2如何生成?
这个.vscode
并非是原本就有的,需要手动生成。生成过程如下:
就可以自动生成了launch.json了。
2.3 配置launch.json文件
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "flat", //debug 中显示的名字
"type": "python", // 文件类型
"request": "launch",
"program": "flat_main.py", //执行的是哪个个文件
"console": "integratedTerminal",
"args": ["--dataset","tianchi","--status","train"], //参数是什么?
"env": {"CUDA_VISIBLE_DEVICES":"2"}, //使用哪块显卡
"justMyCode": false, //是否只是在自己的代码中debug
"cwd": "/home/liushen/program/Flat-Lattice-Transformer/V1" //切换目录
},
//如果有多个可运行代码需要调试,那么就可以使用多个配置项
{
"name": "utils",
"type": "python",
"request": "launch",
"program": "utils.py",
"console": "integratedTerminal",
"env": {"CUDA_VISIBLE_DEVICES":"0"},
"justMyCode": false
}
]
}
3.自动补全
ctrl+shift+p
=> preference :open settings.json
,然后在settings.json 文件中写入如下内容:
"editor.quickSuggestions": {
"other": true,
"comments": false,
"strings": false
}
重启vscode。
4.debug 时variable 窗口的Local加载十分缓慢
问题: 如上所述
解决方法:
点击这个点,然后勾选 variables。就表示在debug时不再传输这个 variables 了。
5. tricks
vscode
是用来写程序+调程序的,如果是运行代码,则交给sh脚本放在后台运行,切忌不要用vscode run 整个程序,并且在windows 窗口上等待结果的的返回。
参考文章
- https://blog.csdn.net/sdaujz/article/details/110404865