Monday, September 5, 2011

Re: How can I select multiple lines that are not in a continuous chunk?

On 09/05/11 00:53, Kay Z wrote:
> I was trying to align using Tabularize plugin:
>
> 1. name1="Woof"
> 2. lucky_dog = lucky( "dog_one"= name1,
> 3. "dog_two"= name1 )
> 4. name2="Howl"
>
> I wanted it to align like this:
>
> 1. name1 = "Woof"
> 2. lucky_dog = lucky( "dog_one"= name1,
> 3. "dog_two"= name1 )
> 4. name2 = "Howl"
>
> But I cannot do so because Tabularize will take third line into consideration, and align everything into:
>
> 1.name1 = "Woof"
> 2.lucky_dog = lucky( "dog_one"= name1,
> 3. "dog_two" = name1 )
> 4.name2 = "Howl"
>
> I believe I could think of some regex trick to archive the
> desired results, it just occurred to me at first that maybe I
> could simply select line 1,2,4 and make those align.

The examples make it much clearer—thanks! While I'm not
personally familiar with the Tabularize plugin, you might be able
to do something like

:'<,'>g/^\</.Tabularize

(assuming there's a ":{range}Tabularize" command. However for
that to work, it might require the ability to see the entire
block at the same time. If so, a couple other options occur to me:

1) use a decorate-tabularize-undecorate pattern, something like

:'<,'>v/^\</-j!
:'<,'>Tabularize
:'<,'>s/,/,\r /g

where the first one pulls everything onto its own line, the
second one does the tabularization, and the third one puts things
back on their own lines. Adjust accordingly for your own code.

2) use a regexp something like

:%s/^\<\(\w\+\)\s*=\s*\(.*\)/\=printf('%*s= %s', 20,
submatch(1), submatch(2))

where "20" is the position/column of the "=" you want to align to.


I hope this gives you some options that help you out...

-tim


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

No comments:

Post a Comment