如何在 Visual Studio Code (VSCode) 中格式化代码? [英] How do you format code in Visual Studio Code (VSCode)?

查看:71
本文介绍了如何在 Visual Studio Code (VSCode) 中格式化代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Ctrl + K + FCtrl + K + D 在 Windows 上的 Visual Studio 中用于格式化,或在 Visual Studio Code 编辑器中美化"代码?

解决方案

在 Visual Studio Code 中可以通过以下快捷方式进行代码格式化:

  • 在 Windows 上 Shift + Alt + F
  • 在 Mac 上 Shift + Option + F
  • 在 Linux 上 Ctrl + Shift + I

或者,您可以使用 Ctrl +Shift+ P 通过编辑器中提供的命令面板"找到快捷方式以及其他快捷方式(或 Command + Shift + P 在 Mac 上),然后搜索格式文档.

对于未保存的片段

  1. 打开命令面板(Win:F1Ctrl+Shift+P)

  2. 找到更改语言模型"

  3. 选择语言,例如json.现在语法应该突出显示.

  4. 格式化文档(例如打开命令面板 -> '格式化文档')

取消格式

  1. 选择文本
  2. 命令面板 ->加入行

'显示图片'

What is the equivalent of Ctrl + K + F and Ctrl + K + D on Windows in Visual Studio for formatting, or "beautifying" code in the Visual Studio Code editor?

解决方案

The code formatting is available in Visual Studio Code through the following shortcuts:

  • On Windows Shift + Alt + F
  • On Mac Shift + Option + F
  • On Linux Ctrl + Shift + I

Alternatively, you can find the shortcut, as well as other shortcuts, through the 'Command Palette' provided in the editor with Ctrl +Shift+ P (or Command + Shift + P on Mac), and then searching for format document.

For unsaved snippets

  1. Open command palette (Win: F1 or Ctrl+Shift+P)

  2. Find 'Change Language Model'

  3. Select language e.g. json. By now syntax should be highlighted.

  4. Format document (e.g. Open Command Palette -> 'Format Document')

Unformat

  1. Select text
  2. Command Palette -> Join Lines

'Show the pics'

这篇关于如何在 Visual Studio Code (VSCode) 中格式化代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆