govisual-studio-codegofmt

vscode-go input tabs of size 4 instead 8


I have Visual Studio Code Insiders installed. Basically I've installed Go extension from Microsoft and written simple hello world app. Now I always use spaces to indent my code, but I saw that it changed to tabs of size 4. So I thought: yay, what a nice extension, now I can start to write my code.

Then I remembered, that the default code indent from gofmt should be 8 as tabs. And I checked. gofmt main.go indeed outputs my code with tabs of size 8. But vscode keeps doing tabs of size 4. I thought maybe it doesn't even call gofmt but when I go RPM->Format document with - it actually does. But still, tabs of size 4. What am I doing wrong in this scenario?

    "editor.renderWhitespace": "all",
    "editor.fontFamily": "Hack",
    "editor.fontSize": 12,
    "editor.minimap.enabled": false,
    "editor.fontLigatures": true,
    "workbench.editor.enablePreview": false,
    "editor.formatOnSave": true,
    "editor.formatOnPaste": true,
    "editor.cursorSmoothCaretAnimation": true,
    "editor.detectIndentation": false

Those my only editor settings and I dont have any custom settings regarding Go extension


Solution

  • go fmt uses tab characters ("\t") to indent the beginning of a line. How a tab is displayed (tab width) is up to your text editor or IDE. I have Tab Width set to 4 in my text editors. My terminal program uses a tab width of 8.

    For example, for xed,

    Editor Preferences

    Tabs

    Use the Tab width spin box to specify the width of the space that xed inserts when you press the Tab key.

    Select the Insert spaces instead of tabs option to specify that xed inserts spaces instead of a tab character when you press the Tab key.