简体   繁体   English

Visual Studio代码格式化程序

[英]Visual Studio code formatter

I'm using Visual Studio 2008 for doing work in C# and JavaScript (AJAXy stuff). 我正在使用Visual Studio 2008在C#和JavaScript(AJAXy的东西)中工作。

Here's my issue -- I love Eclipse and especially the code formatted (Ctrl-Shift-F). 这是我的问题 - 我喜欢Eclipse,特别是格式化的代码(Ctrl-Shift-F)。 Visual Studio's Ctrl-k, Ctrl-d, really sucks in comparison, especially for javascript. Visual Studio的Ctrl-k,Ctrl-d,相比之下真的很糟糕,特别是对于javascript。

Is there a way to get VS to behave like the IDE that I miss? 有没有办法让VS像我想念的那样行事?

Go into Tools | 进入工具| Options | 选项| Text Editor and edit the language specific settings to you're liking. 文本编辑器并编辑您喜欢的语言特定设置。 Ctrl-K, Ctrl-D honors these settings, so you can make the code formatter working the way you want. Ctrl-K,Ctrl-D遵循这些设置,因此您可以使代码格式化程序按您希望的方式工作。 There are a ton of options you can change (bracket positioning, spacing, indenting, etc.). 您可以更改大量选项(支架定位,间距,缩进等)。

I use the great Resharper plugin to format my C# code. 我使用伟大的Resharper插件来格式化我的C#代码。 Lots of settings to change to format your code to your liking. 有许多设置需要根据自己的喜好进行格式化。 Can even make one coding standard with Resharper to be used by all your programmers. 甚至可以使用Resharper制作一个编码标准,供所有程序员使用。

As for key bindings, can change those in your options. 至于键绑定,可以在您的选项中更改它们。

以下是visual studio的解决方法:我只需将扩展名重命名为.css,右键单击文档内部并选择“格式化文档”并将其重命名为.js,格式非常好。

go to options > environment > keyboard, find the command Edit.FormatDocument and bind that to ctrl + shift + f 转到选项>环境>键盘,找到命令Edit.FormatDocument并将其绑定到ctrl + shift + f

EDIT: Misread, you can configure how VS formats in options > text editor > (document type). 编辑:误读,您可以在选项>文本编辑器>(文档类型)中配置VS格式的方式。

don't know if you can get it exactly as how eclipse does, but that's where you set your preferences. 不知道你是否可以像eclipse那样完全得到它,但这就是你设置你的偏好的地方。

I have not tried but Resharper has lot of formatting and coding related nice stuff. 我没有尝试,但Resharper有很多格式和编码相关的好东西。 May be you can find something useful there, and you may start loving VS as well. 也许你可以在那里找到有用的东西,你也可以开始爱VS.

Note: Resharper on VS2005 was kind of sluggish. 注意:VS2005上的Resharper有些迟钝。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM