Wow, thanks Tim! It works fine, except by the case when the last rule doesn't have a semicolon in the end. So I tried to add (?=) perl alike feature in your pattern to make it work and I made it. So, the final pattern I came up with is this one:
:s/\([{;]\|}\&\)\s*/\1\r /g Just added the \|}\& after your square brackets. =] Thanks a ton! On Sat, Feb 21, 2009 at 3:04 PM, Tim Chase <v...@tim.thechases.com> wrote: > >> I guess the title is pretty much self-explanatory. >> But I'll give an example of what I want. Assume I have this line: >> >> a.anything {color:#eee;display:block;width:300px;} >> >> So, I want to split this above line into this: >> >> a.anything { >> color:#eee; >> display:block; >> width:300px; >> >> } >> >> So, what is the best way of doing that? >> Using regexp + substitution? > > Well, my first pass: > > :%s/\([{;]\)\s*/\1\r /g > > does a pretty simple version of what you describe. It's pretty > dumb, so there are some caveats: > > 1) it indents the closing "}" as well...a 2nd post-processing > pass could clean this up: > > :%s/^\s*}\s*$ > > 2) if for some reason you have a "{" or a ";" in a *value* > instead of as a token, it will get treated the same way: > > a.foo{font-name:"colon;brace{ malformed font-name";} > > (highly unlikely, but at least possible) > > 3) if more than one CSS declaration is on the same line: > > a.foo{color:#f00;} a.bar{color:#ba5;} > > you won't get a break after the "}". Though you can add this to > the set of characters if you want to force a line-break after > them too: > > :%s/\([{};]\)\s*/\1\r /g > > 4) if your trailing CSS element has no semicolon, the closing > brace ("}") won't get moved to the next line: > > a.foo{color:#f00;display:block} > > I don't remember off the top of my head whether CSS requires > trailing semicolons, but I seem to recall browsers being somewhat > gracious regarding the omission. > > However, one of the above expressions should get you fairly close > to what you want. > > -tim > > > > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message from the "vim_use" maillist. For more information, visit http://www.vim.org/maillist.php -~----------~----~----~----~------~----~------~--~---