Vetur: Make scaffold snippet follow `tabSize`

Created on 4 Feb 2018  路  10Comments  路  Source: vuejs/vetur

  • [X] I have searched through existing issues
  • [X] I have read through docs
  • [X] I have read FAQ

Info

  • Platform: Ubuntu 16.04
  • Vetur version: 0.11.7
  • VS Code version: 1.19.3

Problem

Typing template and pressing TAB doesn't respect the file indentation settings. Even if I have it set at 4 spaces (both in the file and with .editorconfig, it only indents by 2.

spaces-vetur

Reproducible Case

  1. Set a blank .vue file to 4 space indentation.
  2. Type template on the first line and hit TAB.

Expected behavior: I want to end up between two <template> tags indented by four spaces.
Actual behavior: I end up between two <template> tags indented by two spaces.

This is my first day using VS Code. I don't know how VS Code does it, but I think that in Sublime Text 3, if you indent with tabs in the template, ST3 will convert the tabs to whatever indentation is specified for that file.

bug completion

Most helpful comment

In my .vue file, indentation in template tag is 4 spaces, but in script tag, indentation is 2spaces.
In my user setting, I set "editor.tabSize": 4.
I tried setting "editor.detectIndentation": true, but there are also 2 spaces.

All 10 comments

First, you need this setting: "vetur.format.defaultFormatter.html": "js-beautify-html"

Second, we don't read from .editorconfig. Try setting editor.tabSize to 4.

Thanks for the reply. It's already set to 4 spaces (see the screenshot in the bottom right corner). What should vetur.format.defaultFormatter.html be set to in order for it to read the correct indentation settings?

Thanks. It says "tabSize and insertSpaces are read from editor.tabSize and editor.insertSpaces." but vetur isn't reading the correct indentation settings. I have it set to 4 but it's only indenting by 2.

OK...Do you have a global editor.tabSize set as 4?

If so, what's happening is you have

  "editor.detectIndentation": true

which is the default.

When you run this command
Cmd+Shift+P -> Indent Using Spaces
It's probably saying 2 spaces.

You can turn it off by setting the detectIndentation as false.

When I run Indent using spaces it's shows that it's set to 4 spaces like this, but vetur still only indents by 2. Is that what you mean?

code-vetur

Oh I see what you mean...The scaffold snippets instead of formatting.

I believe this could be fixed by simply replacing the space indentation in the snippets with \t -- that's what I use for my own custom snippets and VS Code automatically converts it to the right number of spaces.

This is fixed by #685.

In my .vue file, indentation in template tag is 4 spaces, but in script tag, indentation is 2spaces.
In my user setting, I set "editor.tabSize": 4.
I tried setting "editor.detectIndentation": true, but there are also 2 spaces.

Was this page helpful?
0 / 5 - 0 ratings