Visual Studio Code使用Python 3.6.8
官网:https://code.visualstudio.com/
settings.json
作用:VS Code 的用户和工作区设置文件,用于自定义编辑器的所有行为、外观和功能。
- Windows 全局设置:
%APPDATA%\Code\User\settings.json - Linux 全局设置
~/.config/Code/User/settings.json - 项目局部设置:项目根目录下的
.vscode/settings.json

{ // 自动保存 "files.autoSave": "afterDelay", "files.autoSaveDelay": 1000, // 文件排除 "files.exclude": { "**/node_modules": true, "**/.git": true, "**/dist": true, "**/build": true, "**/*.js.map": true }, // 搜索排除 "search.exclude": { "**/node_modules": true, "**/bower_components": true, "**/dist": true }, // 代码格式化 "editor.formatOnSave": true, "editor.formatOnPaste": true, "editor.codeActionsOnSave": { "source.fixAll": true, "source.organizeImports": true }, // 自动补全和建议 "editor.suggestSelection": "first", "editor.wordBasedSuggestions": "allDocuments", "editor.quickSuggestions": { "other": true, "comments": false, "strings": true } }
常用插件

| Remote - SSH | 远程连接Linux进行运行、调试 |
| Snazzy Operator Plus | 好用的主题 |
| Git Graph | Git 图形化视图 |
| Python |
安装2022.10.0之前的版本 1、老版本才能进行Debug |
| Pylance |
安装2022.8.10及之前版本 |
常用快捷键
| 放大/缩小 | Ctrl+ \ Ctrl - |
| 当前文件搜索 | Ctrl+F |
| 全局搜索 | Ctrl+Shift+F |
| 注释 | Ctrl+/ |
| 搜索设置 | 点击设置,Ctrl+, |
| 命令面板(万能快捷键) | Ctrl+Shift+P |
| 打开终端 | Ctrl + ` |
| 打开新终端 | Ctrl + Shift+ ` |
| 打开新窗口 | Ctrl+Shift+N |
|
Go to Definition 跳转到定义位置 |
Ctrl+鼠标左键 |
| Go to References Find All References 查找所有引用 |
鼠标右键菜单中 |
| 返回之前\之后位置 | Alt+<或> |
常用设置
导入导出配置:点击左小角 齿轮设置 -> Profile(Import、Export)
关闭VS code更新:Update: Mode = none
开启删除终端确认:Window: Confirm Before Close = always
开启退出询问:Confirm On Exit = always
开启自动保存:Auto Save = afterDelay
版本控制
准备
- 拥有Gitlab仓库权限(Developer才能提交代码)
- 配置Gitlab SSH Keys(本地+远端)
- 克隆仓库
- 修改代码
- 提交:先pull、在Commit(包含add到暂存区)、Push
忽略版本控制
- 项目根目录创建.gitignore
- .gitignore写入忽略版本控制的内容(支持正则表达式)
- 某些文件已被 Git 追踪,修改.gitignore 后不会自动生效,需要手动清除
- git rm --cached <file-name>
调试代码
使用调试配置文件
- 路径:.vscode\launch.json
- Ctrl+Shift+D 打开调试菜单
- 点击齿轮打开launch.json、修改内容

-
- name:配置名称,显示在调试下拉列表中
- type:调式器类型(python--原生调试器、debugpy--三方插件Python Debugger、debugpy-old等)
- request:launch(启动程序)
- program:运行的程序文件路径(${file}表示当前打开在使用的文件)
- console:控制台类型
- justMyCode:调试是否进入源码
- cwd:工作目录(${fileDirname}表示当前文件所在的目录)
- args:配置传入的命令行参数
- 打开需要调试的文件,左键设置断点,选择调试配置(name= "Python: Current File"),点击运行进行配置


{ "version": "0.2.0", "configurations": [ { "name": "Python: Current File", "type": "python", "request": "launch", "program": "${file}", "console": "integratedTerminal", "justMyCode": true, "args": [ "--moduleManager=False", ], } ] }
- 运行调试

- 查看变量

- function-函数、class-类
远程调试
- 添加SSH Host、再连接到Host

- Open Folder

- 安装相关插件(注意版本要求)

- 配置launch.json,执行调试
报错处理
- cannot read properties of undefined reading resolveEnvironment:把pylance降到和python插件一样的版本、不使用Python Debugger
本文来自博客园,作者:Fēngwèi,转载请注明原文链接:https://www.cnblogs.com/fengwei-blogs/p/19169379

浙公网安备 33010602011771号