Visual Studio用引号将选择换行吗? [英] Visual Studio wrap selection in quotes?

查看:154
本文介绍了Visual Studio用引号将选择换行吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以用引号将选定的文本块包装起来?在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:

  1. 单击File,然后单击New,然后选择XML的文件类型.
  2. File菜单上,单击Save.
  3. Save as框中,选择All Files (*.*).
  4. File name框中,输入带有.snippet文件扩展名的文件名.
  5. 单击Save.
  6. 将此代码添加到文件中.
  1. Click File and then click New, and choose a file type of XML.
  2. On the File menu, click Save .
  3. In the Save as box, select All Files (*.*).
  4. In the File name box, enter a file name with the .snippet file name extension.
  5. Click Save.
  6. 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>

保存文件.

  1. 打开Tools-> Code Snippets Manager.
  2. 在语言"部分中,选择"Visual C#".
  3. 单击Import并浏览到您刚刚创建的代码段.
  4. 选中My Code Snippets,然后依次单击FinishOK.
  1. Open Tools -> Code Snippets Manager.
  2. In Language section select "Visual C#".
  3. Click Import and browse to the snippet you just created.
  4. Check My Code Snippets and click Finish and then OK.

要使用它:选择文本->右键单击->选择环绕..."->我的代码段-> 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屋!

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