Skip to content

Instantly share code, notes, and snippets.

@arlodesign
Last active January 13, 2016 22:53
Show Gist options
  • Save arlodesign/e2f784dca3ab8da092dd to your computer and use it in GitHub Desktop.
Save arlodesign/e2f784dca3ab8da092dd to your computer and use it in GitHub Desktop.
Add line breaks before nested selectors when running CSSComb in Sublime Text

Problem

At Sprout, we use CSSComb to sort our declarations and conform our SCSS to our guidelines. One rule that CSSComb can't enforce for us automatically, however, is a line break before a nested selector. Let's fix it in Sublime Text.

How it works

Now, CTRL-SHIFT-C will run CSSComb and add extra linebreaks before nested selectors. NEATO.

[
{
"keys": ["ctrl+shift+c"],
"command": "chain",
"args": {
"commands": [
["css_comb"],
["reg_replace", {"replacements": ["css_spaceout", "css_spacein"]}]
]
}
}
]
{
"replacements": {
"css_spaceout": {
"find": ";\\n(\\s+[&\\-\\.#\\w:,\\>\\s\\+]+\\s+\\{)",
"replace": ";\\n\\n\\1",
"greedy": true,
"case": false
},
"css_spacein": {
"find": "\\n\\n\\n+",
"replace": "\\n\\n",
"greedy": true,
"case": false
}
},
"selection_only": true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment