2012-04-13 92 views

回答

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

相关问题