How to Alphabetize a CSS file in Vim

Posted by Kev on Stack Overflow See other posts from Stack Overflow or by Kev
Published on 2010-06-16T04:51:38Z Indexed on 2010/06/16 6:42 UTC
Read the original article Hit count: 216

Filed under:
|

I get a CSS file:

div#header h1 {
    z-index: 101;
    color: #000;
    position: relative;
    line-height: 24px;
    margin-right: 48px;
    border-bottom: 1px solid #dedede;
    font-size: 18px;
}

div#header h2 {
    z-index: 101;
    color: #000;
    position: relative;
    line-height: 24px;
    margin-right: 48px;
    border-bottom: 1px solid #dedede;
    font-size: 18px;
}

I want to Alphabetize lines between the {...}

div#header h1 {
    border-bottom: 1px solid #dedede;
    color: #000;
    font-size: 18px;
    line-height: 24px;
    margin-right: 48px;
    position: relative;
    z-index: 101;
}

div#header h2 {
    border-bottom: 1px solid #dedede;
    color: #000;
    font-size: 18px;
    line-height: 24px;
    margin-right: 48px;
    position: relative;
    z-index: 101;
}

I map F7 to do it

nmap <F7> /{/+1<CR>vi{:sort<CR>

But I need to press F7 over and over again to get the work done.
If the CSS file is big, It's time-consuming & easily get bored.
I want to get the cmds piped. So that, I only press F7 once!
Any idea? thanks!

© Stack Overflow or respective owner

Related posts about vim

Related posts about gvim