developer tip

Visual Studio Code : 형식이 들여 쓰기 설정을 사용하지 않습니다

optionbox 2020. 7. 24. 20:37
반응형

Visual Studio Code : 형식이 들여 쓰기 설정을 사용하지 않습니다


Format CodeVisual Studio Code에서 명령을 사용할 때 들여 쓰기 설정 ( "editor.tabSize": 2)을 따르지 않습니다 . 대신 탭 크기 4를 사용하고 있습니다. 왜 이런 일이 일어나고 있습니까?

감사!


서식 지정에 사용할 공간 수는 다른 위치에서 가져옵니다. 버전 1.0을 사용하고 있으며이를 해결하기 위해 수행 한 작업입니다 (탭 대신 공백을 사용한다고 가정합니다).

오른쪽의 편집기 하단에서 "공백 : #"을 클릭하십시오.

오른쪽의 상태 표시 줄

그런 다음 메뉴가 맨 위에 나타납니다. "공백 들여 쓰기"를 선택하십시오 :

들여 쓰기 유형 선택

마지막으로 파일을 들여 쓰기 할 공간 수를 선택할 수 있습니다.

탭 크기 선택

다음에 파일을 포맷 할 때 구성한 간격을 확보 할 수 있어야합니다.


Visual Studio Code는 기본값별로 현재 들여 쓰기를 감지하고이를 사용하여 .editorconfig를 무시합니다.

"editor.detectIndentation"false로 설정하십시오.

(파일-> 환경 설정-> 설정)

스크린 샷


@Maleki의 답변이 효과가 없다면 .editorconfig프로젝트 폴더에 파일 이 있는지 확인하십시오 .

예를 들어 Angular CLI는 다음과 같은 새 프로젝트로 생성합니다

# Editor configuration, see http://editorconfig.org
root = true

[*]
charset = utf-8
indent_style = space
indent_size = 2
insert_final_newline = true
trim_trailing_whitespace = true

[*.md]
max_line_length = off
trim_trailing_whitespace = false

작업 공간 또는 사용자 설정의 indent_size내용을 무시하는 것처럼 여기를 변경 해야합니다 .vscode.


나 자신을 위해이 문제는 prettier작업 공간에 더 예쁜 구성 파일이없는 VSCode 플러그인 을 사용하여 발생했습니다 .

플러그인을 비활성화하면 문제가 해결되었습니다. 더 예쁜 구성에 의존하여 수정되었을 수도 있습니다.


If you're using a plugin (in my case Vetur, for vue.js), these may set their own tab formatting settings.

Open your settings, search for "format" and look through relevant plugin settings that may be overwriting the global tab format. This worked for me; once I updated Vetur tab settings to match my preference (4-size tabs in my case), formatting .vue documents started to work properly:

여기에 이미지 설명을 입력하십시오


the settings below solved my issue

  "editor.detectIndentation": false,
  "editor.insertSpaces": false,
  "editor.tabSize": 2,

Most likely you have some formatting extension installed, e.g. JS-CSS-HTML Formatter.

If it is the case, then just open Command Palette, type "Formatter" and select Formatter Config. Then edit the value of "indent_size" as you like.

P.S. Don't forget to restart Visual Studio Code after editing :)


If you came here from google because tab isnt indenting, this can also be because "Tab Moves Focus" is on. It is at the bottom right, and if you have a large enough monitor you may miss it despite it being highlighted.

여기에 이미지 설명을 입력하십시오

Click the Green area or Ctrl + M to make it stop. I'm not sure it can be disabled entirely, then again I dont know why a code editor would want to mess with something like indenting.


I had a similar problem -- no matter what I did I couldn't get the tabsize to stick at 2, even though it is in my user settings -- that ended up being due to the EditorConfig extension. It looks for a .editorconfig file in your current working directory and, if it doesn't find one (or the one it finds doesn't specify root=true), it will continue looking at parent directories until it finds one.

Turns out I had a .editorconfig in a parent directory of the dir I put all my new code projects in, and it specified a tabSize of 4. Deleting that file fixed my issue.


I sometimes have this same problem. VSCode will just suddenly lose it's mind and completely ignore any indentation setting I tell it, even though it's been indenting the same file just fine all day.

I have editor.tabSize set to 2 (as well as editor.formatOnSave set to true). When VSCode messes up a file, I use the options at the bottom of the editor to change indentation type and size, hoping something will work, but VSCode insists on actually using an indent size of 4.

The fix? Restart VSCode. It should come back with the indent status showing something wrong (in my case, 4). For me, I had to change the setting and then save for it to actually make the change, but that's probably because of my editor.formatOnSave setting.

I haven't figured out why it happens, but for me it's usually when I'm editing a nested object in a JS file. It will suddenly do very strange indentation within the object, even though I've been working in that file for a while and it's been indenting just fine.


The VSCode plugin Vetur; used for VueJS applications was overriding the setting for me.

Setting vetur.format.options.tabSize to my preferred number of spaces made it work.


I think vscode is using autopep8 to format .py by default.

"PEP 8 -- Style Guide for Python Code | Python.org"

이 웹 사이트에 따르면 다음은 vscode가 항상 4 개의 공백을 사용하는 이유를 설명합니다.

들여 쓰기 레벨 당 4 개의 공백을 사용하십시오.


모든 플러그인을 비활성화합니다 (그런 다음 하나씩 활성화하고 확인)

참고 URL : https://stackoverflow.com/questions/36251820/visual-studio-code-format-is-not-using-indent-settings

반응형