Visual Studio Codeを使用する際に、タブとスペースの変換係数をカスタマイズする方法を教えてください。
例えば、現在のHTMLでは、TABを押すごとに2つのスペースが生成されるように見えますが、TypeScriptでは4つになります。
デフォルトでは、Visual Studio Codeは、開いているファイルに応じてインデントのオプションを推測します。
インデントの推測は、"editor.detectIndentation": false
でオフにすることができます。
Windowsの場合は、メニューのFile → Preferences → User Settings、Mac*の場合は、メニューのCode → Preferences → Settings* または ⌘,
の3つの設定で、簡単にカスタマイズすることができます。
// The number of spaces a tab is equal to. This setting is overridden
// based on the file contents when `editor.detectIndentation` is true.
"editor.tabSize": 4,
// Insert spaces when pressing Tab. This setting is overriden
// based on the file contents when `editor.detectIndentation` is true.
"editor.insertSpaces": true,
// When opening a file, `editor.tabSize` and `editor.insertSpaces`
// will be detected based on the file contents. Set to false to keep
// the values you've explicitly set, above.
"editor.detectIndentation": false
私はバージョン1.21を使用していますが、それ以前のバージョンにも当てはまるのではないかと思います。
画面の右下を見てみましょう。Spaces」または「Tab-Size」と書かれたものが見えるはずです。
1.スペース」(または「タブサイズ」)をクリックします。 2.スペースを使ったインデント」または「タブを使ったインデント」を選択する 3.お好みのスペースまたはタブの量を選択してください。
これはプロジェクト全体ではなく、ドキュメントごとにしか機能しません。プロジェクト全体に適用したい場合は、ユーザー設定に "editor.detectIndentation": false
を追加する必要があります。