Friday, January 8, 2016

Re: Find adjacent lines starting with same pattern


On Jan 8, 2016 6:26 AM, "Yannick Schall" <yannick@bishbashbosh.it> wrote:
>
> Hi there
>
> I'm optimising a css file.
> I run the file through csscomb to clean it up and i would like to highlight duplicated properties.
>
> ex:
>
> body {
>   margin: 10px;
>   padding: 10px;
>   padding: 20px;
>   background: #fff;
> }
>
> I can find duplicated lines with:
>   /^\(.*\)\n\1$
>
> I can match and capture the properties on every lines:
>   \S\{-}:\)
>
> I can match the whole line and capture the properties and value:
>   \(\S\{-}:\)\(.\{-};\)
>
> But if i try to to apply the pattern on the next line ( \n\1 ) it doesn't match anything:
>   \(\S\{-}:\)\(.\{-};\)\n\1
>
> Is there a way to do that?

All your expressions herein start with \S and don't take the leading indent into consideration. The next line doesn't start with 'padding', but rather '  padding'.

Even where you are matching, you aren't matching from the beginning of the line, but from the first non blank character.

You need ...\n\s*\1 to skip over the next line's initial whitespace.

Salman

>
> Thanks a lot
>
> --
> --
> You received this message from the "vim_use" maillist.
> Do not top-post! Type your reply below the text you are replying to.
> For more information, visit http://www.vim.org/maillist.php
>
> ---
> You received this message because you are subscribed to the Google Groups "vim_use" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments: