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.
>>>
>>>>> p.e.
>>>
>>>>> text a
>>>>> text b
>>>>> text c
>>>>> text d
>>>
>>>>> I would like to select a visual block around these 4 pieces of
>>>>> text and remove all leading spaces, how can I do this?
>>> [...]
>>>
>>> :'<,'>s/\%V\s*\%V//
>>>
>>> --
>>> Best,
>>> Ben
>>
>>
>> It still moves the blocks at the right side of current block. (please
>> see my previous message)
>
> I was hoping the spaces-only lines were what you meant... I guess you
> want something like this non-working example:
>
> :'<,'>s/\%V\(\s*\)\(\%(\S\+\s*\)*\)\%V/\2\1/
>
> replace:
> 1: as many leading spaces as present
> 2: followed by optional runs of non-spaces and optional spaces
>
> with:
> 2: the non-leading-space content
> 1: the leading spaces
>
> (essentially: move leading spaces to the end of the block)
>
> 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/
> 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 /\%[
--
Andy
--
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