Development Tip

Visual Studio Code (VSCode)에서 코드 서식을 어떻게 지정합니까?

yourdevel 2020. 9. 27. 14:05
반응형

Visual Studio Code (VSCode)에서 코드 서식을 어떻게 지정합니까?


Visual Studio에서 형식을 지정하거나 Visual Studio 코드 편집기에서 코드를 "미화"하기 위해 Windows Ctrl+ K+ FCtrl+ K+ D해당하는 것은 무엇입니까 ?


코드 서식은 다음 바로 가기를 통해 Visual Studio Code에서 사용할 수 있습니다.

  • Windows에서 Shift+ Alt+F
  • Mac Shift+ Option+F
  • Ubuntu Ctrl+ Shift+에서I

또는 편집기에서 Ctrl+ Shift+ P(또는 Mac의 경우 Command+ Shift+ P)로 제공되는 검색 기능을 통해 바로 가기 및 기타 바로 가기를 찾은 다음 형식 문서 를 검색 할 수 있습니다 .


코드 서식 단축키 :

Windows의 Visual Studio Code- Shift+ Alt+F

MacOS의 Visual Studio Code- Shift+ Option+F

Ubuntu의 Visual Studio 코드- Ctrl+ Shift+I

필요한 경우 기본 설정을 사용하여이 바로 가기를 사용자 지정할 수도 있습니다.

파일 저장 중 코드 서식 :

Visual Studio Code를 사용하면 사용자가 기본 설정을 사용자 지정할 수 있습니다.

저장하는 동안 콘텐츠의 형식을 자동으로 지정하려면 Visual Studio Code의 작업 공간 설정에 아래 코드 조각을 추가합니다.

메뉴 파일환경 설정작업 공간 설정

{
    // Controls if the editor should automatically format the line after typing
    "beautify.onSave": true,

    "editor.formatOnSave": true,

    // You can auto format any files based on the file extensions type.
    "beautify.JSfiles": [
        "js",
        "json",
        "jsbeautifyrc",
        "jshintrc",
        "ts"
    ]
}

참고 : 이제 TypeScript 파일의 형식을 자동으로 지정할 수 있습니다. 내 업데이트를 확인하십시오.


메뉴 파일환경 설정키보드 단축키 에서 키 바인딩을 추가 할 수 있습니다 .

{ "key": "cmd+k cmd+d", "command": "editor.action.formatDocument" }

또는 Visual Studio 와 같은 :

{ "key": "ctrl+k ctrl+d", "command": "editor.action.formatDocument" }

  1. 파일을 마우스 오른쪽 버튼으로 클릭
  2. 선택 형식의 문서 ( Alt+ Shift+ F또는 Alt+ Shift+ I리눅스) 메뉴 상자에서.

여기에 이미지 설명 입력


올바른 키 조합은 Shift+ Alt+ F입니다.


Fedora의 경우

  1. File-> Preferences->를 클릭합니다 Keyboard shortcuts.
  2. 에서 Default Keyboard Shortcuts( Ctrl+ F)를 검색 합니다 editor.action.format.

내 읽기 "key": "ctrl+shift+i"

변경할 수도 있습니다. 방법에 대한 이 답변참조하십시오 ... 또는 위로 스크롤하는 것이 조금 게으른 경우 :


"환경 설정-> 키보드 단축키"에서 키 바인딩을 추가 할 수 있습니다.

{ "key": "cmd+k cmd+d", "command": "editor.action.format" }

또는 Visual Studio와 같은 :

{ "key": "ctrl+k ctrl+d", "command": "editor.action.format" }


참고 : cmd키는 Mac 전용입니다. Windows 및 Fedora (Windows 키보드)의 경우Ctrl


수정 :

Visual Code 버전에 따라 1.28.2이것이 내가 찾은 것입니다.

editor.action.format더 이상 존재하지 않다. 이제 editor.action.formatDocument로 대체되었습니다 editor.action.formatSelection.

editor.action.format기존 바로 가기를 보려면 검색 상자에 입력 하십시오.

키 조합을 변경하려면 다음 단계를 따르십시오.

  1. 클릭 editor.action.formatDocument또는editor.action.formatSelection
  2. 펜과 같은 아이콘이 왼쪽에 나타납니다. 클릭하십시오.
  3. 팝업이 나타납니다. 원하는 키 조합을 누르고 Enter를 누르십시오.

Linux에서는 Ctrl+ Shift+ I입니다.

Windows에서는 Alt+ Shift+ F입니다. HTML / CSS / JavaScript 및 Visual Studio Code 1.18.0으로 테스트되었습니다.

다른 언어의 경우 특정 언어 패키지를 설치해야 할 수 있습니다.


Visual Studio Code 1.6.1설치된 관련 포맷터 확장을 자동으로 선택하고 저장할 때마다 전체 문서의 서식을 지정 하는 " Format On Save "를 지원합니다 .

설정하여 "저장시 포맷"활성화

"editor.formatOnSave": true

사용 가능한 바로 가기 키 (Visual Studio Code 1.7 이상)가 있습니다.

전체 문서 서식 지정 : Shift+ Alt+F

형식 선택 만 : Ctrl+ K, Ctrl+F


우분투에서는 Ctrl+ Shift+ I입니다.


텍스트를 마우스 오른쪽 버튼으로 클릭하고 "코드 서식"을 선택하십시오.

Visual Studio Code는 js-beautify내부적으로 사용 하지만 사용하려는 스타일을 수정할 수있는 기능이 없습니다. 확장 "미화"를 사용하면 설정을 추가 할 수 있습니다.


어떤 이유로 Alt+ Shift+ F가 Mac Visual Studio Code 1.3.1에서 작동하지 않았고 실제로 "문서 서식"명령이 전혀 작동하지 않았습니다. 그러나 명령 Formatter 는 매우 잘 작동했습니다.

따라서 Command+ Shift+ 를 사용 P하고 Formatter를 입력 하거나 메뉴 FilePreferencesKeyboard ShortcutsCommand+ K Command+에서 원하는 바로 가기를 S만든 다음 Formatter 를 입력 하고 바로 가기를 추가 할 수 있습니다.

예를 참조하십시오.

여기에 이미지 설명 입력


Shift+ Alt+ F는 1.17.2 이상에서 잘 작동합니다.


Visual Studio에서 코드 서식 지정.

Windows 8에서 포맷을 시도했습니다.

아래 스크린 샷을 따르십시오.

  1. 상단 메뉴 모음에서보기를 클릭 한 다음 명령 팔레트를 클릭합니다.

    여기에 이미지 설명 입력

  2. 그런 다음 형식이 필요한 곳에 텍스트 상자가 나타납니다.

    Shift+ Alt+F

    여기에 이미지 설명 입력


Mac OS X, DNVMDNXMono설치할 때까지 C #의 형식 바로 가기가 작동하지 않았습니다 .

Mono를 설치하기 전에 자동 포맷 단축키 ( Shift+ Alt+ F)는 .json파일에 대해서만 작동했습니다 .


Visual Studio를 코드에서, Shift+ Alt+는 F무엇을하고있다 Ctrl+ K+는 DVisual Studio에서하고있다.


Mac에서는 Shift+ Alt+ F가 저에게 적합합니다.

메뉴에서 언제든지 키 바인딩을 확인할 수 있습니다.

메뉴 파일환경 설정키보드 단축키 및 키워드 '형식'으로 필터링.


메뉴 파일환경 설정설정

"editor.formatOnType": true

세미콜론을 입력하면 형식이 지정됩니다.

또는 "editor.formatOnSave": true.


Visual Studio Code의 기본 동작을 변경하려면 확장이 필요하지만 작업 영역 또는 사용자 수준에서 기본 동작을 재정의 할 수 있습니다. 지원되는 대부분의 언어에서 작동합니다 (HTML, JavaScript 및 C #을 보장 할 수 있습니다).

작업 공간 수준

혜택

  • 연장이 필요하지 않습니다
  • 팀간에 공유 가능

결과

  • .vscode/settings.json is created in the project root folder

How To?

  1. Go to: Menu FilePreferencesWorkspace Settings

  2. Add and save "editor.formatOnType": true to settings.json (which overrides default behavior for the project you work on by creating .vscode/settings.json file).

    어떻게 보이는지

User environment level

Benefits

  • Does not requires extension
  • Personal development environment tweeking to rule them all (settings:))

Outcomes

  • User's settings.json is modified (see location by operating system below)

How To?

  1. Go to: menu FilePreferencesUser Settings

  2. Add or change the value of "editor.formatOnType": false to "editor.formatOnType": true in the user settings.json

Your Visual Studio Code user's settings.json location is:

Settings file locations depending on your platform, the user settings file is located here:

  • Windows: %APPDATA%\Code\User\settings.json
  • Mac: $HOME/Library/Application Support/Code/User/settings.json
  • Linux: $HOME/.config/Code/User/settings.json The workspace setting file is located under the .vscode folder in your project.

More details may be found here.


Default this key was not working for me on HTML, CSS, and JavaScript documents.

After searching, I found the popular plugin JS-CSS-HTML Formatter with 133,796 installs.

After installation just reload the windows and hit Ctrl + Shift + F, and it worked!


Select the text, right click on the selection, and select the option "command palette":

여기에 이미지 설명 입력

A new window opens. Search for "format" and select the option which has formatting as per the requirement.


Just install Visual Studio Keymap by Microsoft. Problem Solved. :p


In Mac, use +K and then +F.


If you want to custom the style of format-document, you should use Beautify extention.

Refer to this screenshot:

img


Simplest way I use in Visual Studio Code (Ubuntu) is:

Select the text which you want to format with the mouse.

Right click and choose "Format selection".


You have to install the appropriate plug-in first (i.e., XML, C#, etc.).

Formatting won't become available until you've installed the relevant plugin, and saved the file with an appropriate extension.


For those that want to customize what JavaScript files to format, you can use the any extension on the JSfiles property. The same applies to HTML.

{
    "beautify.onSave": true,
    "beautify.JSfiles": ["js", "json", "jsbeautifyrc", "jshintrc", "ts"],
    "beautify.HTMLfiles": ["htm", "html"]
}

This will enable beautify on save for TypeScript, and you can add in XML to the HTML option.


Not this one. Use this:

Menu FilePreferencesWorkspace Settings, "editor.formatOnType": true


Use extension...

Enables auto formatting of the code when you save a file.

Launch Visual Studio Code and Quick Open (Ctrl + P), paste the following command, and press Enter.

ext install format-on-save

https://marketplace.visualstudio.com/items?itemName=gyuha.format-on-save


Visual Studio Code on Linux:

Ctrl+ [코드 블록을 들여 쓰지 않고

Ctrl+ ]대량 들여 쓰기

참고 URL : https://stackoverflow.com/questions/29973357/how-do-you-format-code-in-visual-studio-code-vscode

반응형