VS Code

安装

  1. 下载
  2. 默认安装

插件

  1. Language
  2. vscode-icons
    改变文件图标
  3. Bracket Pair Colorizer
    改变不同层次的括弧颜色
  4. Path Intellisense
    填充路径
  5. Python
  6. Guides
  7. Code Spell Checker
  8. Anaconda Extension Pack
  9. Cmder && Git
    To run Cmder as the VS Code terminal
  10. Setting Sync
    需要记住 GitHub Gist 和 Github Token
  11. leetcode
  12. code-runner

配置

用户设置

1
2
3
4
5
"window.zoomLevel": 0,
"editor.fontSize": 18,
"editor.formatOnSave": true, # 保存时代码格式化
"files.insertFinalNewline": true, # 结尾插入空行
"files.autoSave": "onFocusChange", # 失去焦点时自动保存

Python 设置

1
2
3
4
5
# 代码检查工具设置为flake8
"python.linting.flake8Enabled": true,
"python.linting.pylintEnabled": false,
# 代码格式化工具为yapf
"python.formatting.provider": "yapf",

运行代码(关于 vscode 中的相对路径)

在运行程序时,程序中的相对路径按照 cwd(current work directory)查找文件,而 cwd 的规则如下:
默认情况下,使用 code-runner.cwd 设置
如果 code-runner.cwd 未设置,code-runner.fileDirectoryAsCwd 为 true 使用要执行的文件目录
如果 code-runner.cwd 未设置,code-runner.fileDirectoryAsCwd 则 false 使用在 VS Code 中打开的根文件夹的路径
如果没有打开文件夹,请使用 os temp 文件夹
所以,如果想以程序文件所在位置编写相对路径,需要在设置中加入"code-runner.fileDirectoryAsCwd": true,同时,在 launch.json 中的 configurations 下加入"cwd": "${fileDirname}"