Mic*_*ter 32 python configuration code-formatting visual-studio-code vscode-settings
使用VSCode 1.9.0和(donjayamanne)Python 0.5.8扩展,是否可以提供Python特定的编辑器选项?
或者更一般地说,是否可以提供特定语言的制表符间距和替换规则?例如,Python应该是tab = 4个空格(替换为空格),而Ruby应该是tab = 2个空格(替换).其他语言往往有自己的意见.但是,我只看到将军
"editor.tabSize": 4,
"editor.insertSpaces": true,
Run Code Online (Sandbox Code Playgroud)
选项.
我想也许有一个"python.editor": { }块或者一个"python.editor.tabSize"选项,但是我找不到这样的参考,也没有成功猜到一个工作名称.
zel*_*o_a 69
我今天遇到了同样的问题.
这是我修复它的方式.在VSCode中的setting.json中添加以下行:
"[python]": {
"editor.insertSpaces": true,
"editor.tabSize": 4
}
Run Code Online (Sandbox Code Playgroud)
它就像一个魅力.
Oli*_*ver 37
对于所有发现默认答案没有解决您的问题的人,这里有一个基于vscode github 上的讨论/问题的方法。
问题很可能源于 vscode 及其扩展本身决定如何缩进代码。有些扩展不选择缩进,但其他扩展则选择缩进,更糟糕的是 vscode 似乎“记住”缩进。因此,一旦缩进错误,人们可能会发现建议的答案无法解决您的问题,因为在另一个文件中检测到了不正确的缩进。如果检测到的缩进不符合您的用户设置(即使遵循默认答案),这可能会导致很多挫败感。"editor.detectIndentation" : false幸运的是,修复方法只是通过除了接受的答案指定的值之外添加全局或语言特定设置来关闭此功能。
"[python]": {
"editor.detectIndentation" : false,
"editor.insertSpaces": true,
"editor.tabSize": 4
}
Run Code Online (Sandbox Code Playgroud)
将数字“4”更改为您希望用于缩进的空格数。
点击File > Preferences > Settings
键入settigns.py并单击Edit settings.json[ JSON]部分。
"[python]": {
"editor.insertSpaces": true,
"editor.tabSize": 4
}
Run Code Online (Sandbox Code Playgroud)
Python应该是tab = 4个空格(替换为空格),Ruby应该是tab = 2个空格...
安装编辑器配置插件.
ext install EditorConfig
Run Code Online (Sandbox Code Playgroud)
.editorconfig使用Python和Ruby特定设置将文件添加到项目根目录:
[*.py]
indent_style = space
indent_size = 4
[*.rb]
indent_style = space
indent_size = 2
Run Code Online (Sandbox Code Playgroud)
这些是其他支持的属性:
tab_width
end_of_line
insert_final_newline
trim_trailing_whitespace
Run Code Online (Sandbox Code Playgroud)
也可以看看:
https://github.com/editorconfig/editorconfig-vscode
| 归档时间: |
|
| 查看次数: |
19084 次 |
| 最近记录: |