【问题标题】:Is there any way to get Visual Studio 2010 to put comments in left-most column?有没有办法让 Visual Studio 2010 将评论放在最左边的列中?
【发布时间】:2012-04-26 03:16:21
【问题描述】:

我喜欢将// 的注释掉代码放在最左边的列中,因为这样可以更容易地区分被注释掉的代码和实际的 cmets。 Xcode 使用 cmd+slash 快捷方式执行此操作。

但是,VS2010 中的等效快捷键 ctrl+k+c 总是将// 插入到第一个的左侧行中的字符。例如

有什么方法可以让 VS 按我的意愿行事?

【问题讨论】:

    标签: visual-studio-2010 comments


    【解决方案1】:

    我使用以下宏。如果您选择了很多行进行注释,那会很慢,而且我对编写宏不太熟悉,所以它可能会改进很多,但它对我有用。

    Public Module Module1
        Sub CodeBlocksComment()
            Dim start_line, end_line, temp As Integer
            Dim selection As EnvDTE.TextSelection
            selection = DTE.ActiveDocument.Selection
    
            start_line = selection.TopLine
            end_line = selection.BottomLine
            If end_line < start_line Then
                temp = start_line
                start_line = end_line
                end_line = temp
            End If
    
            If Not start_line = end_line And selection.BottomPoint.AtStartOfLine Then
                end_line -= 1
            End If
    
            DTE.UndoContext.Open("Comment Region")
            Try
                For i = start_line To end_line
                    selection.GotoLine(i)
                    selection.StartOfLine(vsStartOfLineOptions.vsStartOfLineOptionsFirstColumn)
                    selection.Text = "//"
                Next
                selection.GotoLine(start_line)
                selection.StartOfLine(vsStartOfLineOptions.vsStartOfLineOptionsFirstColumn)
                selection.LineDown(True, end_line - start_line + 1)
            Finally
                DTE.UndoContext.Close()
            End Try
        End Sub
    End Module
    

    然后您可以设置任何您想要的键盘快捷键。该命令将被列为Macros.MyMacros.Module1.CodeBlocksComment

    【讨论】:

      猜你喜欢
      • 2019-05-09
      • 1970-01-01
      • 1970-01-01
      • 2011-08-01
      • 2020-04-05
      • 2016-01-10
      • 1970-01-01
      • 2011-02-16
      • 1970-01-01
      相关资源
      最近更新 更多