Skip to content

insertSpaces = auto, new file, first indentation, tab not possible. #1747

Closed

Description

When insertSpaces = auto is set and you create a new file, pressing the tab key will insert spaces rather than a tab character. This is a problematic default because it means there is no easy way to actually get the first tab into the file so the auto can start learning what the file's indentation mechanism is. If you want space indent, you can simply press the space bar a few times to start the learning process. In order to start a new file with tab indentation though you (currently) need to go find another file with a tab in it, copy the tab, and paste it into the new file.

I recommend having the fallback behavior for an empty file be that the space bar inserts spaces and the tab key inserts tabs. This way both camps (spaces and tabs) have the ability to reasonably start new files when in auto-mode.

Activity

  1. MicahZoltu commented on Jan 2, 2016

    @MicahZoltu
    Author

    An alternate option would be to add a setting for empty file default (tab or spaces) and/or add a setting for each file type.

  2. felixfbecker commented on Jan 3, 2016

    @felixfbecker
    Contributor

    I agree this setting is very bad designed. There should be insertSpaces, tabSize and autoDetectIndentation or something like that, with the former being the default for new files and the latter being a boolean if the editor should auto detect these for existing files. This should default to true.

    Or, even better, merge editorconfig extension into core and read values from editorconfig in user home directory.

  3. added
    bug
    on Jan 3, 2016
  4. KichangKim commented on Jan 4, 2016

    @KichangKim

    Strongly agree. When I make Makefile file, I suffered for this issue because Makefile needs Tab indent.

  5. felixfbecker commented on Jan 4, 2016

    @felixfbecker
    Contributor

    @kkc0923 That would be solved when editorconfig gets merged into core, because you can set different settings for different file types via globs.

  6. KichangKim commented on Jan 4, 2016

    @KichangKim

    Felix Becker (@felixfbecker) Does you mean "Editor Config for VS Code" extension? If it is, I'll check it. Thanks.

  7. Tyriar commented on Jan 4, 2016

    @Tyriar
    Contributor

    The default was recently changed from tab to space due to yaml not working with tabs. #498

    I like your solution Felix Becker (@felixfbecker), pulling out "editor.insertSpaces": "auto" into its own config value and allowing specification of fallbacks.

    RE: Editor config, there is currently an extension in the marketplace. It's not fully compatible with .editorconfig files yet I believe due to API limitations, but it does do tab style and size.

  8. MicahZoltu commented on Jan 4, 2016

    @MicahZoltu
    Author

    The .editorconfig extension is not currently compatible with editor.insertSpaces: auto. See https://github.com/Microsoft/vscode-editorconfig/issues/12

  9. SamVerschueren commented on Feb 12, 2016

    @SamVerschueren
    Contributor

    Zoltu (@Zoltu) Use the EditorConfig plugin from EditorConfig itself. Global settings being auto are supported since v0.2.2.

  10. nilzona commented on Mar 15, 2016

    @nilzona

    Sam Verschueren (@SamVerschueren) I have this issue even if I use EditorConfig.
    in my .editorconfig file:

    # 4 tab indentation
    [*.*]
    indent_style = tab
    indent_size = 4
    

    in settings.json (user preferences):

    "editor.insertSpaces": "auto"
    

    Even so, a new file that is created always insert spaces when tabbing.

    I have to paste some code with tabs, close the editor and re-open. Then it picks up the right tab setting.

  11. SamVerschueren commented on Mar 15, 2016

    @SamVerschueren
    Contributor

    Anders Nilsson (@nilzona) Try using [*] instead of [*.*] and make sure you are using the correct plugin. The Microsoft EditorConfig plugin is deprecated in favour of the plugin from the EditorConfig community.

  12. alexdima commented on Mar 15, 2016

    @alexdima
    Member

    In March, there is a new setting editor.detectIndentation = true|false that replaces the usage of "auto" in editor.tabSize and editor.insertSpaces.

    When editor.detectIndentation is true, and the file has sufficient hints (e.g. it is not empty, it contains indented lines), editor.tabSize and editor.insertSpaces will be overwritten. This allows to cover the new file case by using:

    editor.insertSpaces: false,
    editor.tabSize: 4,
    editor.detectIndentation: true
    

    This will make new files use Tabs@4 and existing files will be scanned to detect their indentation.

  13. gertcuykens commented on Sep 12, 2016

    @gertcuykens

    Can there be a exception made for Makefile's :)
    I always use

        "editor.detectIndentation": false,
        "editor.insertSpaces": true,
    

    Even if the previous developer used tab's on the file I don't care I am using spaces :P so I make sure that I disable autodetection. But a Makefile is the only exception where things start breaking if I do that. Can Makefile's have a forced Tab no matter what the settings are?

  14. felixfbecker commented on Sep 12, 2016

    @felixfbecker
    Contributor

    Install the editorconfig extension

  15. locked and limited conversation to collaborators on Nov 18, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugverified

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions