Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 864041
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T09:24:39+00:00 2026-05-15T09:24:39+00:00

Does anybody know if there is a way in Visual Studio 2010 to highlight

  • 0

Does anybody know if there is a way in Visual Studio 2010 to highlight and comment out lines in CSS files like you can with all other files (by clicking a button)? Perhaps a Visual Studio extension? Commenting them manually is cumbersome.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T09:24:40+00:00Added an answer on May 15, 2026 at 9:24 am

    Unfortunately the regular commands for commenting and uncommenting (Ctrl+K+C and Ctrl+K+U) don’t work for CSS. Instead, you’ll need to record or write a macro that does this and attach it to your own shortcut.

    To comment the selected text (note, this is quick and dirty and therefore comments it as a single block):

    Sub CssComment()
        DTE.ActiveDocument.Selection.Text = "/*" + DTE.ActiveDocument.Selection.Text + "*/"
    End Sub
    

    Update
    This new one below works more like the regular comment command and comments on a line-by-line basis. It means you don’t have to select the text before hand. This also does all the changes as a single undoable operation and checks the file extension so that you can assign this to the regular shortcut and it will work for all files.

    Sub CommentCss()
        Dim ts1 As TextSelection = CType(DTE.ActiveDocument.Selection(), EnvDTE.TextSelection)
    
        Dim fileName = DTE.ActiveDocument.FullName
    
        ' We should default to regular commenting if we're not editing CSS.
        ' This allows this macro to be attached to the Ctrl+K+C shortcut
        ' without breaking existing file format commenting.
        If Not fileName.EndsWith(".css") Then
            DTE.ExecuteCommand("Edit.CommentSelection")
            Return
        End If
    
        Dim weOpenedUndo As Boolean = False
        If Not DTE.UndoContext.IsOpen Then
            DTE.UndoContext.Open("CommentCSS")
            weOpenedUndo = True
        End If
    
        ts1.StartOfLine(vsStartOfLineOptions.vsStartOfLineOptionsFirstColumn, True)
        Dim ep1 As EditPoint2 = ts1.TopPoint.CreateEditPoint()
        Dim ep2 As EditPoint2 = ts1.BottomPoint.CreateEditPoint()
    
        While ep1.Line <= ep2.Line
            Dim text As String = ep1.GetLines(ep1.Line, ep1.Line + 1)
            text = text.Trim()
    
            If Not text.StartsWith("/*") Or Not text.EndsWith("*/") Then
                ep1.StartOfLine()
                ep1.Insert("/*")
                ep1.EndOfLine()
                ep1.Insert("*/")
            End If
            Dim lineBeforeDown As Integer = ep1.Line
            ep1.LineDown()
    
            If ep1.Line = lineBeforeDown Then
                Exit While
            End If
        End While
    
        ts1.StartOfLine(vsStartOfLineOptions.vsStartOfLineOptionsFirstColumn, True)
    
        If weOpenedUndo Then
            DTE.UndoContext.Close()
        End If
    End Sub
    

    Update for Uncommenting
    This macro performs the reverse task. Again, it’s implemented so that it will work for all documents if required by checking the file extension and deferring to the standard Edit.UncommentSelection command for non-CSS files.

    Sub UncommentCss()
        Dim ts1 As TextSelection = CType(DTE.ActiveDocument.Selection(), EnvDTE.TextSelection)
        Dim ep1 As EditPoint2 = ts1.TopPoint.CreateEditPoint()
        Dim ep2 As EditPoint2 = ts1.BottomPoint.CreateEditPoint()
    
        Dim fileName = DTE.ActiveDocument.FullName
    
        ' We should default to regular commenting if we're not editing CSS.
        ' This allows this macro to be attached to the Ctrl+K+C shortcut
        ' without breaking existing file format commenting.
        If Not fileName.EndsWith(".css") Then
            DTE.ExecuteCommand("Edit.UncommentSelection")
            Return
        End If
    
        Dim weOpenedUndo As Boolean = False
        If Not DTE.UndoContext.IsOpen Then
            DTE.UndoContext.Open("UncommentCSS")
            weOpenedUndo = True
        End If
    
        While ep1.Line <= ep2.Line
            ep1.StartOfLine()
    
            Dim text As String = ep1.GetLines(ep1.Line, ep1.Line + 1)
            text = text.Trim()
    
            If text.StartsWith("/*") And text.EndsWith("*/") Then
                Dim epEndOfLine As EditPoint2 = ep1.CreateEditPoint()
                epEndOfLine.EndOfLine()
                text = text.Substring(2, text.Length - 4)
                ep1.ReplaceText(epEndOfLine, text, vsEPReplaceTextOptions.vsEPReplaceTextKeepMarkers Or vsEPReplaceTextOptions.vsEPReplaceTextAutoformat)
            End If
    
            Dim lineBeforeDown As Integer = ep1.Line
            ep1.LineDown()
    
            If ep1.Line = lineBeforeDown Then
                Exit While
            End If
        End While
    
        ts1.StartOfLine(vsStartOfLineOptions.vsStartOfLineOptionsFirstColumn, True)
    
        If weOpenedUndo Then
            DTE.UndoContext.Close()
        End If
    End Sub
    

    Update 18Oct2012
    As per dirq’s answer, there is an extension, Web Essentials that provides CSS commenting and uncommenting. I would recommend using this over the macros above as it provides other great support besides just the CSS commenting shortcuts.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anybody know if there is a way to create an SQLite database based
Does anybody know if there is a way to make autocompletion work in MySQL
Does anybody know if there is a way using java to pass all the
Does anybody know if there is a way to understand what users are doing
Does anybody know of a library or piece of software out there that will
We are using Visual Studio 2008 and would like to know if there is
Does anybody know if there is a way of having an image upload field
Does anybody know if there is a way to embed a link inside of
does anybody know if there is a way to do for loops in drools
Does anybody know if it's there any way one can change the mode of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.