how to compare two different regions in the same files?

21 views
Skip to first unread message

yixiao...@gmail.com

unread,
May 12, 2010, 12:57:46 PM5/12/10
to vim_use
Hi,

I want to compare the text in two different parts of the same file.
Instead of cut and paste to create two new files, are there any ways
to directly compare the two parts in vim? I am using vim 7.2.

Thanks

Frank

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

stosss

unread,
May 12, 2010, 2:21:03 PM5/12/10
to vim...@googlegroups.com
On Wed, May 12, 2010 at 12:57 PM, yixiao...@gmail.com
<yixiao...@gmail.com> wrote:
> Hi,
>
> I want to compare the text in two different parts of the same file.
> Instead of cut and paste to create two new files, are there any ways
> to directly compare the two parts in vim? I am using vim 7.2.

Have you tried :help :split

--
"If the American people ever allow private banks to control the issue
of their money, first by inflation and then by deflation, the banks
and corporations that will grow up around them, will deprive the
people of their property until their children will wake up homeless on
the continent their fathers conquered."
-Thomas Jefferson

This has been happening for the last 100 years.

Rajarajan Rajamani

unread,
May 12, 2010, 2:21:54 PM5/12/10
to vim...@googlegroups.com
vimdiff

yixiao...@gmail.com

unread,
May 12, 2010, 2:28:19 PM5/12/10
to vim_use
The split will split the file into two windows. How can I compare the
two regions instead of reading it line by line.

Thanks

Frank

Gary Johnson

unread,
May 12, 2010, 2:34:52 PM5/12/10
to vim_use
On 2010-05-12, yixiao...@gmail.com wrote:
> The split will split the file into two windows. How can I compare the
> two regions instead of reading it line by line.

You can't. Not unless you put the contents of those two windows
into two, new buffers and diff the two buffers. But then any
changes you make to those buffers are not reflected back to the
original file. It would be a nice feature to have, though.

Regards,
Gary

Christian Brabandt

unread,
May 13, 2010, 5:43:11 AM5/13/10
to vim_use
Hi Gary!

On Mi, 12 Mai 2010, Gary Johnson wrote:

> On 2010-05-12, yixiao...@gmail.com wrote:
> > The split will split the file into two windows. How can I compare the
> > two regions instead of reading it line by line.
>
> You can't. Not unless you put the contents of those two windows
> into two, new buffers and diff the two buffers. But then any
> changes you make to those buffers are not reflected back to the
> original file. It would be a nice feature to have, though.

Try the NrrwRgn Plugin on http://github.com/chrisbra/NrrwRgn

I have just added an experimental feature, that allows to have a new
Narrowed Window per file.

The idea is to create a new Narrow Region for each region and file you
want to diff. Be sure to set g:nrrw_rgn_sepwin to 1 so the plugin will
create for each buffer an extra Narrow Window. Then you can diff both
Narrow Windows and whenever you write the narrowed Windows, the changes
will be taken back into the original file.

regards,
Christian
--

Gary Johnson

unread,
May 13, 2010, 4:44:50 PM5/13/10
to vim_use
On 2010-05-13, Christian Brabandt wrote:
> Hi Gary!
>
> On Mi, 12 Mai 2010, Gary Johnson wrote:
>
> > On 2010-05-12, yixiao...@gmail.com wrote:
> > > The split will split the file into two windows. How can I compare the
> > > two regions instead of reading it line by line.
> >
> > You can't. Not unless you put the contents of those two windows
> > into two, new buffers and diff the two buffers. But then any
> > changes you make to those buffers are not reflected back to the
> > original file. It would be a nice feature to have, though.
>
> Try the NrrwRgn Plugin on http://github.com/chrisbra/NrrwRgn
>
> I have just added an experimental feature, that allows to have a new
> Narrowed Window per file.
>
> The idea is to create a new Narrow Region for each region and file you
> want to diff. Be sure to set g:nrrw_rgn_sepwin to 1 so the plugin will
> create for each buffer an extra Narrow Window. Then you can diff both
> Narrow Windows and whenever you write the narrowed Windows, the changes
> will be taken back into the original file.

Very nice! I've just played with it a little and haven't tried
making changes with it, but I like it so far. Thanks.

Regards,
Gary
Reply all
Reply to author
Forward
0 new messages