On Sat, 6 Nov 2010, Andy Wokula wrote:

Am 04.11.2010 18:53, schrieb Benjamin R. Haskell:
On Thu, 4 Nov 2010, rameo wrote:
On Nov 4, 5:33 pm, "Benjamin R. Haskell" wrote:
On Thu, 4 Nov 2010, Benjamin R. Haskell wrote:
On Thu, 4 Nov 2010, rameo wrote:

I find myself often to align blocks of text and thought to create a regex to remove all leading spaces in a block.

[...] I guess you want something like this non-working example:

:'<,'>s/\%V\(\s*\)\(\%(\S\+\s*\)*\)\%V/\2\1/

[...]

It's not working though because something is 'greedy' where I'm not
expecting. Any other regexpers see what I'm doing wrong?

I'd say the pattern \%V still su*** a little bit.

Apparently, \%V does not match right after the last character of the visual area.

Example: If the word WARNING is selected, then /\%V.*\%V will only match WARNIN.

Nevertheless, 'hlsearch' still highlights the whole word: There is one match for "WARNIN" and another (zero-width) match at the "G". The "G" is highlighted because at least one character is always highlighted.

It doesn't matter if 'selection' is set to "inclusive" or "exclusive".

So, I'd try the following:

   :'<,'>s/\%V\(\s*\)\(.\{-}\)\...@!/\2\1/

Clever workaround.  I like it.  Plus, it's more explicit about the greediness:
\s*   = match as many spaces as possible
.\{-} = match as few characters as necessary after that


Another attempt fails for even weirder reasons:

:'<,'>s/\%V\(\s*\)\(\%[\S.*]\)\%V/\2\1/

E64: star follows nothing
E476: invalid command

Is \%[] compiled internally to something else? (Otherwise I see a \s* and .*, in both cases the '*' follows something.)

  :h /\%[

I looked there, but didn't see anything that explains this. The only limitations I see listed are:

"""
There can be no \(\), \%(\) or \z(\) items inside the [] and \%[] does not nest.
"""

I don't have any \(\), \%(\), or \z(\) items, and the \%[] doesn't contain another \%[] sequence. So why is \%[\S.*] invalid? I suspect it's that \%[] can't contain anything from :h /multi, but I don't see where that's stated.

...Finally found it. /atom != /piece. piece = atom | atom multi. So, now it's just that the error message is confusing. "\%[] can only contain /ordinary-atoms" would be clearer in the docs.

--
Best,
Ben

--
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

Reply via email to