Visual Studio用引号将选择换行吗? [英] Visual Studio wrap selection in quotes?
问题描述
是否可以用引号将选定的文本块包装起来?在Visual Studio中,我没有找到扩展或插件,我只是在寻找一种简单的方法来做.有没有添加该功能的方法?
Is there is a way to wrap a selected text block with quotes? In visual studio I have not found a extension or plugin I am just looking for a simple way to do it. Is there a way to add that functionality?
推荐答案
Visual Studio中也提供了环绕"选项,也没有ReSharper.它不包含使用引号引起来的选项.但是可以使用自定义包装程序扩展代码片段.也用双引号引起来.为此:
The "Surround with" option is available in Visual Studio also without ReSharper. It doesn't contain the option to wrap in quotes. But it's possible to extend the snippets with custom wrappers. Also with double quotes. To do that:
- 单击
File
,然后单击New
,然后选择XML
的文件类型. - 在
File
菜单上,单击Save
. - 在
Save as
框中,选择All Files (*.*)
. - 在
File name
框中,输入带有.snippet
文件扩展名的文件名. - 单击
Save
. - 将此代码添加到文件中.
- Click
File
and then clickNew
, and choose a file type ofXML
. - On the
File
menu, clickSave
. - In the
Save as
box, selectAll Files (*.*)
. - In the
File name
box, enter a file name with the.snippet
file name extension. - Click
Save
. - Add this code to the file.
代码
<CodeSnippet Format="1.1.0" xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<Header>
<Title>doubleQuotes</Title>
<Author>Microsoft Corporation</Author>
<Shortcut>"</Shortcut>
<Description>Wrap in double quotes</Description>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
<SnippetType>SurroundsWith</SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>selected</ID>
<ToolTip>content</ToolTip>
<Default>content</Default>
</Literal>
</Declarations>
<Code Language="CSharp">"$selected$"</Code>
</Snippet>
</CodeSnippet>
保存文件.
- 打开
Tools
->Code Snippets Manager
. - 在语言"部分中,选择"Visual C#".
- 单击
Import
并浏览到您刚刚创建的代码段. - 选中
My Code Snippets
,然后依次单击Finish
和OK
.
- Open
Tools
->Code Snippets Manager
. - In Language section select "Visual C#".
- Click
Import
and browse to the snippet you just created. - Check
My Code Snippets
and clickFinish
and thenOK
.
要使用它:选择文本->右键单击->选择环绕..."->我的代码段-> doubleQoutes
To use it: Select text -> right click -> select "Surround with..." -> My Code Snippets -> doubleQoutes
或者:选择文本->点击 Ctrl + K , S ->我的代码段-> doubleQoutes
Alternatively: Select text -> hit Ctrl + K, S -> My Code Snippets -> doubleQoutes
我从此答案中了解了该解决方案的想法,作者在其中展示了如何将代码包装在自定义html标记中.
I got the idea for this solution from this answer where the author shows how to wrap code in custom html tags.
这篇关于Visual Studio用引号将选择换行吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!