LoginSignup
85
48

More than 3 years have passed since last update.

【Visual Studio Code】特定のファイルだけタブのスペース数が違うとき

Last updated at Posted at 2017-03-24

VisualStudioCodeのTipsです。

ほかの人が新しく追加したファイルのインデントが4スペースになっていたので2スペースにするためにフォーマットをかけましたが修正できない、ということが起こりました。
確かに、タブを打つと4スペース入ってしまいます。
私の環境では2スペースにしてあるはずなので、editor.tabSizeの設定を確認しました。
ちゃんと2となっています。
他のファイルではタブは2スペースとして入力されます。

調べてみると、以下の設定をする必要がありました。

"editor.detectIndentation": false

editor.detectIndentationtrueになっていると、開いたファイルに基づいてeditor.tabSizeeditor.insertSpacesが決まってしまいます。
editor.detectIndentationはデフォルトでtrueとなっています。

このファイルを新規作成した人が、タブを4スペース設定で使っていた、かつ、私の環境でeditor.detectIndentationtrueになっていたので、私の環境でもこのファイルのみタブが4スペースになってしまっていました。
editor.detectIndentationfalseにしてフォーマットをかけたところ、きちんと修正できました。

設定方法
1. VisualStudiCode左上の「ファイル」>「基本設定」>「設定」→エディタ部分に「settings.json」が開く
2. エディタ右側に「"editor.detectIndentation": false」を書き、保存する
settings.PNG

85
48
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
85
48