VScode automatic indentation & indent guides, and tabulation size (editor.tabSize)

Viewed 1063

I have file using an indentation level of 4 columns, and assuming that a tabulation character corresponds to 8 spaces, like this (I use . to represent a space, and <------> for a tabulation character):

class Foo {
....void bar() {
<------>if (boz) {
<------>....return x;
<------>}
....}
}

This is common for certain coding styles like 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).

I'm having trouble rendering this properly with VSCode:

  • If I set editor.tabSize to 4, then it renders badly as
class Foo {
....void bar() {
<-->if (boz) {
<-->....return x;
<-->}
....}
}
  • If I set editor.tabSize to 8, then the text is rendered properly, but the indentation guides are incorrect (a guide is missing for the void bar() indentation level):

indentation guides

More importantly, automatic indentation (pressing the "tab" key, or on-the-fly indentation when pressing "return" after a { character) now indents with 8 columns, making the editor barely usable.

An obvious workaround is to use only spaces for indenting, but this is not applicable when opening a pre-existing file.

Is there a way to configure the indentation guides to be displayed every 4 columns, while still rendering tabs every 8 columns?

In the editorconfig cross-editor configuration file specification, this corresponds to the tab_width and indent_size properties, that I would like to be able to change independently.

I'm a former Emacs-user, and this would correspond to tab-width and c-basic-offset for example.

1 Answers

Unfortunately, as of now there is no setting or extension that is based only on (spaces/tabs-at-the-current-tab-size).

Related