Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Does anyone know of a VS2010 extension for CSS regions? I have some pretty big CSS files and I can't seem to locate how to create regions for these. I have a JavaScript region extension but not one for CSS?

share|improve this question
I have the same inquiry. I logged this issue at -…. I got a message saying the issue was resolved, but nothing further. Not sure what that all meant? Perhaps they've released an extension for it? I'm quite lost. – jonathanconway Aug 15 '10 at 6:47

You could try the JavaScript collapse macro and change the //#region for /*#region*/


Of course you should create a new macro and copy/paste the same script.

Option Strict Off
Option Explicit Off

Imports System
Imports EnvDTE
Imports EnvDTE80
Imports System.Diagnostics
Imports System.Collections

Public Module JsMacros

Sub OutlineCssRegion()
    Dim selection As EnvDTE.TextSelection = DTE.ActiveDocument.Selection

    'Const REGION_START As String = "//#region"
    'Const REGION_END As String = "//#endregion"
    Const REGION_START As String = "/*#region*/"
    Const REGION_END As String = "/*#endregion*/"

    Dim text As String = selection.Text

    Dim startIndex As Integer
    Dim endIndex As Integer
    Dim lastIndex As Integer = 0
    Dim startRegions As Stack = New Stack()

        startIndex = text.IndexOf(REGION_START, lastIndex)
        endIndex = text.IndexOf(REGION_END, lastIndex)

        If startIndex = -1 AndAlso endIndex = -1 Then
            Exit Do
        End If

        If startIndex <> -1 AndAlso startIndex < endIndex Then
            lastIndex = startIndex + 1
            ' Outline region ...
            selection.MoveToLineAndOffset(CalcLineNumber(text, CInt(startRegions.Pop())), 1)
            selection.MoveToLineAndOffset(CalcLineNumber(text, endIndex) + 1, 1, True)

            lastIndex = endIndex + 1
        End If

End Sub

Private Function CalcLineNumber(ByVal text As String, ByVal index As Integer)
    Dim lineNumber As Integer = 1
    Dim i As Integer = 0

    While i < index
        If text.Chars(i) = vbCr Then
            lineNumber += 1
            i += 1
        End If

        i += 1
    End While

    Return lineNumber
End Function

End Module
share|improve this answer

This is an old post, but I thought I'd follow up since it still appears as a top result in Google (VS CSS Regions).

See - this extension allows for class and region collapsing with CSS files within VS 2010.


/* #region Generic class collection */

.GenericClass {
    border: 1px solid #000000;

.GenericClass2 {
    border: 2px solid #000000;

/* #endregion */
share|improve this answer

This feature has finally made it to Visual Studio 2012. :)

Usage is as @Bjorn Aadnesgaard describes.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .