[英]Is there a format code shortcut for Visual Studio?
To answer the specific question, in C# you are likely to be using the C# keyboard mapping scheme, which will use these hotkeys by default:要回答具体问题,在 C# 中您可能会使用 C# 键盘映射方案,默认情况下将使用这些热键:
Ctrl + E , Ctrl + D to format the entire document. Ctrl + E , Ctrl + D格式化整个文档。
Ctrl + E , Ctrl + F to format the selection. Ctrl + E , Ctrl + F格式化选择。
You can change these in menu Tools → Options → Environment → Keyboard (either by selecting a different "keyboard mapping scheme", or binding individual keys to the commands "Edit.FormatDocument" and "Edit.FormatSelection").您可以在菜单工具→选项→环境→键盘中更改这些(通过选择不同的“键盘映射方案”,或将单个键绑定到命令“Edit.FormatDocument”和“Edit.FormatSelection”)。
If you have not chosen to use the C# keyboard mapping scheme, then you may find the key shortcuts are different .如果您没有选择使用 C# 键盘映射方案,那么您可能会发现快捷键不同。 For example, if you are not using the C# bindings, the keys are likely to be:例如,如果您不使用 C# 绑定,则键可能是:
Ctrl + K + D (Entire document) Ctrl + K + D (整个文档)
Ctrl + K + F (Selection only) Ctrl + K + F (仅限选择)
To find out which key bindings apply in your copy of Visual Studio, look in menu Edit → Advanced menu - the keys are displayed to the right of the menu items, so it's easy to discover what they are on your system.要找出适用于您的 Visual Studio 副本的键绑定,请查看菜单编辑→高级菜单- 键显示在菜单项的右侧,因此很容易发现它们在您的系统上是什么。
(Please do not edit this answer to change the key bindings above to what your system has!) (请不要编辑此答案以将上面的键绑定更改为您的系统所拥有的!)
Ctrl + K + D (Entire document) Ctrl + K + D (整个文档)
Ctrl + K + F (Selection only) Ctrl + K + F (仅限选择)
尝试Ctrl + K + D (不要在两者之间抬起Ctrl键)。
Yes, you can use the two-chord hotkey ( Ctrl + K , Ctrl + F if you're using the General profile) to format your selection.是的,您可以使用双和弦热键( Ctrl + K ,如果您使用的是常规配置文件,则为Ctrl + F )来格式化您的选择。
Other formatting options are under menu Edit → Advanced , and like all Visual Studio commands, you can set your own hotkey via menu Tools → Options → Environment → Keyboard (the format selection command is called Edit.FormatSelection
).其他格式化选项位于菜单Edit → Advanced下,并且像所有 Visual Studio 命令一样,您可以通过菜单Tools → Options → Environment → Keyboard设置自己的热键(格式选择命令称为Edit.FormatSelection
)。
Formatting doesn't do anything with blank lines, but it will indent your code according to some rules that are usually slightly off from what you probably want.格式化对空行没有任何作用,但它会根据一些通常与您可能想要的内容略有不同的规则缩进您的代码。
To align the text in the proper format -以正确的格式对齐文本 -
Ctrl + K + D for front end pages like .aspx
or .cshtml
Ctrl + K + D用于.aspx
或.cshtml
等前端页面
Ctrl + K + F for a .cs
page .cs
页面的Ctrl + K + F
But observe to press all buttons in sequence...但请注意按顺序按下所有按钮...
Format the entire document:格式化整个文档:
Ctrl + K + D Ctrl + K + D
For Visual Studio Code
Use ALt + Shift + F对于Visual Studio Code
,使用ALT + Shift + F
for Visual Studio IDE
Press Ctrl + K followed by Ctrl + D对于Visual Studio IDE
按Ctrl + K ,然后按Ctrl + D
It will beautify/format your entire file.它将美化/格式化您的整个文件。
选择文档中的所有文本,然后按Ctrl + E + D 。
Change these shortcuts in Visual Studio在 Visual Studio 中更改这些快捷方式
Tools → Options → Environment → Keyboard
and then change the command然后更改命令
"Edit.FormatDocument" or "Edit.FormatSelection"
assign the same shortcut alt + shift +f
as in visual studio code in order to not remember another one and confuse between each other.分配与 Visual Studio 代码中相同的快捷键alt + shift +f
,以免记住另一个快捷键并相互混淆。
Most easy, try once最简单,试一次
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.