Python
安装black
- 打开
vscode,新建一个.py文件,按下快捷键Shift+Alt+F,右下角会弹出如下窗口,选择Use black。

如果没有弹出窗口,应该是该项目已经设置了默认的格式化库。只需要打开项目目录下
.vscode/settings.json这个文件,把里面的"python.formatting.provider": "***"删除,然后重复刚刚的步骤即可。
- 打开
.vscode/setting.json文件,添加如下配置。{"python.formatting.provider": "black","python.formatting.blackArgs": ["--line-length", "280", // 单行最大长度// "--skip-string-normalization", // 默认所有字符串使用双引号,取消该注释则忽略该问题],}
以上设置只对指定项目生效,如果想对所有python项目都应用该配置,在vscode的全局设置添加上面的配置项即可。
保存自动整理import
添加vscode配置
"[python]": {// 在保存 python 文件的时候,用isort进行import 排序"editor.codeActionsOnSave": {"source.organizeImports": true}},// isort排序时,代码宽度是自行指定的,其设置值如下"python.sortImports.args": ["-l","280"]
找个python文件,直接保存检查头部import部分是否发生变化,如果没有变化,可能需要全局安装
isortsudo pip3 install isort
Vue
安装VSCode插件
安装
Vetur与ESLint插件

- 添加
setting.json配置信息{// 每次保存的时候将代码按eslint格式进行修复"[vue]": {"editor.codeActionsOnSave": {"source.fixAll.eslint": true}},"[html]": {"editor.codeActionsOnSave": {"source.fixAll.eslint": true}},"[css]": {"editor.codeActionsOnSave": {"source.fixAll.eslint": true}},"[less]": {"editor.codeActionsOnSave": {"source.fixAll.eslint": true}},"[javascript]": {"editor.codeActionsOnSave": {"source.fixAll.eslint": true}}}
完整的
setting.json设置{/********************************************************************* 编辑器 设置相关 *********************************************************************/// 关闭右侧迷你地图滚动"editor.minimap.enabled": false,// 当按tab键是,用空格代替// PS: 开启这个可以充分避免因为tab键和space键混用而导致的代码一团糟// 特别是在编写python代码的时候 XD"editor.insertSpaces": true,// 按住 Ctrl 键并滚动鼠标滚轮时对编辑器字体大小进行缩放// 如在meeting适,share屏幕下VS Code字体太小,就能进行调节"editor.mouseWheelZoom": true,// 显示控制字符// 这个也非常有用,有时候一些看不到的特殊字符可能会让你debug半天"editor.renderControlCharacters": true,// 显示空白字符// 我使用的是 boundary 模式,这样可以比较清晰地看到每行开头和结尾的空格字符"editor.renderWhitespace": "boundary",// 文件的EOL,统一成 "\n",// see https://stackoverflow.com/questions/1552749/difference-between-cr-lf-lf-and-cr-line-break-types// 避免不同平台之间出现诸如"^M"等问题"files.eol": "\n",// vscode默认启用了根据文件类型自动设置tabsize的选项"editor.detectIndentation": false,// 重新设定tabsize"editor.tabSize": 2,/********************************************************************* Python 设置相关 *********************************************************************/"python.formatting.provider": "black","python.formatting.blackArgs": ["--line-length","280", // 单行最大长度// "--skip-string-normalization", // 默认所有字符串使用双引号,取消该注释则忽略该问题],"[python]": {// 在保存时对代码进行格式化"editor.formatOnSave": true,// 在保存 python 文件的时候,用isort进行import 排序"editor.codeActionsOnSave": {"source.organizeImports": true}},// isort排序时,代码宽度是自行指定的,其设置值如下"python.sortImports.args": ["-l","280"],/************************************************************************ 前端 设置相关 *********************************************************************/// 每次保存的时候将代码按eslint格式进行修复"[vue]": {"editor.codeActionsOnSave": {"source.fixAll.eslint": true}},"[html]": {"editor.codeActionsOnSave": {"source.fixAll.eslint": true}},"[css]": {"editor.codeActionsOnSave": {"source.fixAll.eslint": true}},"[less]": {"editor.codeActionsOnSave": {"source.fixAll.eslint": true}},"[javascript]": {"editor.codeActionsOnSave": {"source.fixAll.eslint": true}}}
