Adjacent Block Putting

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Adjacent Block Putting

Gundala Viswanath
Dear Vimmers,

Given this two texts:

xxxxxxx
xxxxxxx

And

yyyyyyy
yyyyyyy

How can I combine it into

 yyyyyyy xxxxxxx
 yyyyyyy xxxxxxx

Yes, with one spacing in between.
Is there a quick way to do it in VIM?

--
Gundala Viswanath
Reply | Threaded
Open this post in threaded view
|

Re: Adjacent Block Putting

Tim Chase-2
> Given this two texts:

Are the two texts in two files, or in two areas of the same file?
  And, if it matters, do you want to move the "yyyy" or the
"xxxx" portion?  If they're in diff. files, you'll have to switch
buffers between the yanking/deleting of the first steps and the
pasting portion.

> How can I combine it into
>
>  yyyyyyy xxxxxxx
>  yyyyyyy xxxxxxx
>
> Yes, with one spacing in between.
> Is there a quick way to do it in VIM?

The easy way to do it would be to make use of block-wise
visual-mode copying and pasting.  To move the "yyy" to the "xxx"
portion, use control+V, and select the block of "yyy"s.  Use "y"
or "d" to either yank or delete the "yyy"s.  Then move to the
beginning of your block of "xxx" and use "P" to paste it.  This
doesn't add the spaces.  However, you can then go to the
beginning of the "xxx"s and use control+V again to select the
first "x" in each line of the block of "xxx"s, and use "I"
(capital-eye) to insert a space and then hit escape.

Alternatively, you can add the space first:

select your range of "yyy"s and do

        :'<,'>s/$/ /

Then use control+V to select the "yyy"s and the trailing space.
Paste with "P" as above, before the block of "xxx"s.

The method for moving the "xxx"s to the "yyy"s would be similar.


For more information, read up on

        :help blockwise-visual
        :he blockwise-register
        :he blockwise-examples
        :he blockwise-operators

-tim





Reply | Threaded
Open this post in threaded view
|

Re: Adjacent Block Putting

Yakov Lerner
In reply to this post by Gundala Viswanath
On Wed, 8 Feb 2006 21:48:29 +0800, "Gundala Viswanath"
<[hidden email]> said:

> Dear Vimmers,
>
> Given this two texts:
>
> xxxxxxx
> xxxxxxx
>
> And
>
> yyyyyyy
> yyyyyyy
>
> How can I combine it into
>
>  yyyyyyy xxxxxxx
>  yyyyyyy xxxxxxx
>

Assuming second pair of lines immediately follows first pair of
lines, and you put cursor on the 1st line of the 1st pair,
have this mapping

:map <f2> jddpJkkJ

and press F2 and you are done. This assumes we are dealing with 4 lines
exactly.

Yakov
--
 
  [hidden email]

--
http://www.fastmail.fm - Access all of your messages and folders
                          wherever you are

Reply | Threaded
Open this post in threaded view
|

Re: Adjacent Block Putting

Charles E Campbell Jr
In reply to this post by Tim Chase-2
Tim Chase wrote:

> ...
> The easy way to do it would be to make use of block-wise visual-mode
> copying and pasting.  To move the "yyy" to the "xxx" portion, use
> control+V, and select the block of "yyy"s.  Use "y" or "d" to either
> yank or delete the "yyy"s.  Then move to the beginning of your block
> of "xxx" and use "P" to paste it.  This doesn't add the spaces.  
> However, you can then go to the beginning of the "xxx"s and use
> control+V again to select the first "x" in each line of the block of
> "xxx"s, and use "I" (capital-eye) to insert a space and then hit escape.

...

In addition to Tim's excellent explanation -- if you

  :set ve=all

then you can use visual block mode as Tim said

  ctrl-v (move to opposite corner) x
 (move to desired location, one space to the right of the xxxx-block) p

The virtual edit setting allows you to put the cursor to the right of
the text; when you paste the spaces in the column will be kept.

Regards,
Chip Campbell

Reply | Threaded
Open this post in threaded view
|

Re: Adjacent Block Putting

William Pursell
In reply to this post by Gundala Viswanath
Gundala Viswanath wrote:

> Dear Vimmers,
>
> Given this two texts:
>
> xxxxxxx
> xxxxxxx
>
> And
>
> yyyyyyy
> yyyyyyy
>
> How can I combine it into
>
>  yyyyyyy xxxxxxx
>  yyyyyyy xxxxxxx
>
> Yes, with one spacing in between.
> Is there a quick way to do it in VIM?

I've been trying to train my fingers to use :g more, and here's
a solution that works if you have the text in lines 1-4 of the buffer:
:1m3|1m4|1,4g/[xy]/j

There are 2 things I don't like about this solution:
1) I'm tied to the absolute line numbers.  I had a hard time
when trying to match address in distinguishing between the
first line of 'xxxx' and the 2nd line.  Any good thoughts on
accomplishing that?

2) I don't like the [xy] in the pattern match.  What's a better
way to do that?
Reply | Threaded
Open this post in threaded view
|

Re: Adjacent Block Putting

Benji Fisher
On Fri, Feb 10, 2006 at 07:51:50AM +0000, bill wrote:

> Gundala Viswanath wrote:
> >Dear Vimmers,
> >
> >Given this two texts:
> >
> >xxxxxxx
> >xxxxxxx
> >
> >And
> >
> >yyyyyyy
> >yyyyyyy
> >
> >How can I combine it into
> >
> > yyyyyyy xxxxxxx
> > yyyyyyy xxxxxxx
> >
> >Yes, with one spacing in between.
> >Is there a quick way to do it in VIM?
>
> I've been trying to train my fingers to use :g more, and here's
> a solution that works if you have the text in lines 1-4 of the buffer:
> :1m3|1m4|1,4g/[xy]/j
>
> There are 2 things I don't like about this solution:
> 1) I'm tied to the absolute line numbers.  I had a hard time
> when trying to match address in distinguishing between the
> first line of 'xxxx' and the 2nd line.  Any good thoughts on
> accomplishing that?

     Mark the top of the x's with mark a and the top of the y's with
mark b.  Then

:'b,'b+1g/./execute "copy" (2*line('.') - 2*line("'b") + line("'a"))
:'b,'b+1d

Variant:  set mark a, then select the lines of y's in Visual mode and
use '< instead of 'b and '> instead of 'b+1 .

> 2) I don't like the [xy] in the pattern match.  What's a better
> way to do that?

     Figure out the correct range and then :g/./j or :g/^/j .  The
second works even with empty lines, which does not matter here.  In
fact, why not :g//j (saving one precious character ... along the same
lines, you can use "t" instead of "copy" if that is your goal).

HTH --Benji Fisher