visual-studio-code - VScode 自动缩进和缩进指南,以及制表大小 (editor.tabSize)

标签 visual-studio-code indentation

我有一个使用 4 列缩进级别的文件,并假设一个制表符对应于 8 个空格,如下所示(我使用 . 表示一个空格,而 <------> 表示一个制表符):

class Foo {
....void bar() {
<------>if (boz) {
<------>....return x;
<------>}
....}
}
这对于某些编码风格很常见,例如 Oracle coding conventions for Java :

Four spaces should be used as the unit of indentation. The exact construction of the indentation (spaces vs. tabs) is unspecified. Tabs must be set exactly every 8 spaces (not 4).


我无法使用 VSCode 正确呈现它:
  • 如果我设置 editor.tabSize到 4,然后它呈现为
  • class Foo {
    ....void bar() {
    <-->if (boz) {
    <-->....return x;
    <-->}
    ....}
    }
    
  • 如果我设置 editor.tabSize到 8,然后文本正确呈现,但缩进指南不正确(void bar() 缩进级别缺少指南):

  • indentation guides
    更重要的是,自动缩进(按“tab”键,或在 { 字符后按“返回”时即时缩进)现在缩进 8 列,使编辑器几乎无法使用。
    一个明显的解决方法是仅使用空格进行缩进,但这在打开预先存在的文件时不适用。
    有没有办法将缩进指南配置为每 4 列显示一次,同时仍然每 8 列呈现选项卡?
    editorconfig跨编辑器配置文件规范,这对应于tab_widthindent_size属性,我希望能够独立更改。
    我是前 Emacs 用户,这对应于 tab-widthc-basic-offset例如。

    最佳答案

    不幸的是,到目前为止,还没有仅基于 (spaces/tabs-at-the-current-tab-size) 的设置或扩展。

    关于visual-studio-code - VScode 自动缩进和缩进指南,以及制表大小 (editor.tabSize),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63391233/

    相关文章:

    emacs - Emacs 中的 CoffeeScript 缩进问题

    debugging - VSCode 调试 golang。深入调试器

    notepad++ - Notepad++ 中的自动缩进

    markdown - 如何在markdown中插入缩进

    visual-studio-code - VSCode : `editor.tokenColorCustomizations` > `comment` does not color the whole comment

    javascript - vim JavaScript 缩进插件 - 命令是什么?

    language-design - 解析 "off-side"(基于缩进)的语言

    visual-studio-code - VS Code 更新删除了扩展

    c# - 如何让 VSCode 使用 C# 7 而不是 C# 4?

    node.js - 运行各种 Node 命令的 VSCode 任务