简体   繁体   English

在VS 2008中评论CSS的快捷方式

[英]Shortcut for commenting CSS in VS 2008

When I press the standard Ctrl + E, C (an other variants) in VS2008 whilst editing a CSS file, it says that command is not available. 当我在编辑CSS文件的同时按下VS2008中的标准Ctrl + E,C(其他变体)时,它说该命令不可用。 How do I setup a shortcut to apply a plain old /* */ comment to selected text in VS? 如何设置快捷方式以将简单的旧/ * * /注释应用于VS中的选定文本? Thanks 谢谢

Within Visual Studio, hit Alt-F11 to open the Macro IDE and add a new module by right-clicking on MyMacros and selecting Add|Add Module... 在Visual Studio中,按Alt-F11打开宏IDE并通过右键单击MyMacros并选择添加|添加模块来添加新模块...

Paste the following in the source editor: 将以下内容粘贴到源编辑器中:

Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports System.Diagnostics

Public Module CommentCSS
    Sub CommentCSS()
        Dim selection As TextSelection
        selection = DTE.ActiveDocument.Selection

        Dim selectedText As String
        selectedText = selection.Text

        If selectedText.Length > 0 Then
            selection.Text = "/*" + selectedText + "*/"
        End If
    End Sub
End Module

You can create a keyboard shortcut by going to Tools|Options... and selecting Keyboard under the Environment section in the navigation on the left. 您可以通过转到“工具”|“选项...”并在左侧导航中的“ 环境”部分下选择“ 键盘”来创建键盘快捷键。 Select your macro and assign any shortcut you like. 选择您的宏并指定您喜欢的任何快捷方式。

You can also add your macro to a menu or toolbar by going to Tools|Customize... and selecting the Macros section in the navigation on the left. 您还可以通过转到“工具”|“自定义...”并选择左侧导航中的“ 宏”部分,将宏添加到菜单或工具栏中。 Once you locate your macro in the list, you can drag it to any menu or toolbar, where it its text or icon can be customized to whatever you want. 在列表中找到宏后,您可以将其拖动到任何菜单或工具栏,在其中可以将文本或图标自定义为您想要的任何内容。

here's an even simpler solution: 这是一个更简单的解决方案:

Sub CommentCSS()
    DTE.ActiveDocument.Selection.StartOfLine(VsStartOfLineOptions.VsStartOfLineOptionsFirstText)
    DTE.ActiveDocument.Selection.Text = "/*"
    DTE.ActiveDocument.Selection.EndOfLine()
    DTE.ActiveDocument.Selection.Text = "*/"
End Sub

you can record it yourself using ctrl+shift+R 你可以使用ctrl + shift + R自己录制

  1. place the cursor on the line you want to comment 将光标放在要评论的行上
  2. press "Home" on your keyboard 按键盘上的“主页”
  3. type /* 类型/ *
  4. press "End" on your keyboard 按键盘上的“结束”
  5. type */ 类型* /
  6. save your recording 保存录音

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

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