vimdiff usage

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

vimdiff usage

Mark Volkmann-2
I'm just learning how to use vimdiff to find the difference between
two files. I know there are many ways to start it. I'm interested in
using it after I already have vim running. Here's what I did.

- open first file
- ":sp" to split the window
- open second file in second window
- ":diffthis" in both buffers
- "]c" to move to next difference
- "[c" to move to previous difference

That seemed to work fine. Then I wanted to turn it off, so I did this.

- ":set nodiff" in both buffers
- ":set noscrollbind" in both buffers

Is there an easier way to set it up or turn it off?

--
R. Mark Volkmann
Partner, Object Computing, Inc.
Reply | Threaded
Open this post in threaded view
|

Re: vimdiff usage

Gary Johnson
On 2005-09-30, Mark Volkmann <[hidden email]> wrote:

> I'm just learning how to use vimdiff to find the difference between
> two files. I know there are many ways to start it. I'm interested in
> using it after I already have vim running. Here's what I did.
>
> - open first file
> - ":sp" to split the window
> - open second file in second window
> - ":diffthis" in both buffers
> - "]c" to move to next difference
> - "[c" to move to previous difference
>
> That seemed to work fine. Then I wanted to turn it off, so I did this.
>
> - ":set nodiff" in both buffers
> - ":set noscrollbind" in both buffers
>
> Is there an easier way to set it up ...

    - open first file
    - ":diffsplit" <name of second file>

I prefer

    - ":vert diffsplit" <name of second file>

as the second step myself.

> ...or turn it off?

I think there may be in vim 7, but not vim 6.  Here's what I have in
my .vimrc:

-----------------------------------------------------------------
" Reset everything set by the diff mode.
" (See ":help diff".)
"
if v:version >= 602
    command! -bar -bang Nodiff wincmd l <bar> only<bang> <bar> set nodiff noscrollbind scrollopt-=hor wrap foldcolumn=0 virtualedit=
else
    command! -bar Nodiff exe 'wincmd l' <bar> only <bar> set nodiff noscrollbind wrap foldcolumn=0 scrollopt-=hor virtualedit=
endif

" Set virtualedit=all whenever diff mode is entered.
"
au FilterWritePre * if &diff | set virtualedit=all | endif
-----------------------------------------------------------------

HTH,
Gary

--
Gary Johnson                 | Agilent Technologies
[hidden email]     | Wireless Division
                             | Spokane, Washington, USA
Reply | Threaded
Open this post in threaded view
|

Re: vimdiff usage

Yegappan Lakshmanan
On 9/30/05, Gary Johnson <[hidden email]> wrote:
> On 2005-09-30, Mark Volkmann <[hidden email]> wrote:
>
> > ...or turn it off?
>
> I think there may be in vim 7, but not vim 6.  Here's what I have in
> my .vimrc:
>

In Vim7, you can use the ":diffoff" command. From the Vim help:

:diffoff        Switch off diff mode for the current window.

:diffoff!       Switch off diff mode for all windows.

The ":diffoff" command resets the relevant options to their default value.
This may be different from what the values were before diff mode was started,
the old values are not remembered.

        'diff'          off
        'scrollbind'    off
        'scrollopt'     without "hor"
        'wrap'          on
        'foldmethod'    "manual"
        'foldcolumn'    0

- Yegappan
Reply | Threaded
Open this post in threaded view
|

RE: vimdiff usage

Keith W. Roberts
In reply to this post by Mark Volkmann-2
----Original Message----
From: Mark Volkmann [mailto:[hidden email]]
Sent: Friday, September 30, 2005 3:40 PM
To: [hidden email]
Subject: vimdiff usage

> I'm just learning how to use vimdiff to find the difference between
> two files. I know there are many ways to start it. I'm interested in
> using it after I already have vim running. Here's what I did.
>
> - open first file
> - ":sp" to split the window
> - open second file in second window
> - ":diffthis" in both buffers
> - "]c" to move to next difference
> - "[c" to move to previous difference
>
> That seemed to work fine. Then I wanted to turn it off, so I did this.
>
> - ":set nodiff" in both buffers
> - ":set noscrollbind" in both buffers
>
> Is there an easier way to set it up or turn it off?

I just use the following:

        " un-diff the current buffer/window
        noremap ,nd  :set nodiff fdc=0 \| norm zR<CR>

I don't care if the folds stay there; I just don't want to see 'em.  And if
I do :set fdc=2 they become visible again; sometimes handy.

For multiple windows:

        :windo :norm ,nd

-Keith

Reply | Threaded
Open this post in threaded view
|

RE: vimdiff usage

David Fishburn
In reply to this post by Mark Volkmann-2
 

> -----Original Message-----
> From: Mark Volkmann [mailto:[hidden email]]
> Sent: Friday, September 30, 2005 6:40 PM
> To: [hidden email]
> Subject: vimdiff usage
>
> I'm just learning how to use vimdiff to find the difference
> between two files. I know there are many ways to start it.
> I'm interested in using it after I already have vim running.
> Here's what I did.
>
> - open first file
> - ":sp" to split the window
> - open second file in second window
> - ":diffthis" in both buffers
> - "]c" to move to next difference
> - "[c" to move to previous difference
>
> That seemed to work fine. Then I wanted to turn it off, so I did this.
>
> - ":set nodiff" in both buffers
> - ":set noscrollbind" in both buffers
>
> Is there an easier way to set it up or turn it off?

You have had some good responses, I will just show you what I do.

In my virmce, I have the MyDiff function.  I put the following additional
lines in it:
    " Show a usage message as a reminder for the diff
    " specific key mappings
    " See Nodiff below which resets this value
    if !exists('g:diff_msg_shown')
        let g:diff_msg_shown = 0
    endif

    if g:diff_msg_shown == 0
        echo "Diff key mappings\n".
                    \ "-----------------\n".
                    \ "]c - next diff\n".
                    \ "[c - prev diff\n".
                    \ "do - diff obtain - get change from other window\n".
                    \ "dp - diff put    - put change into other window\n"
        " This function is called once for each buffer involved
        " in the diff, so only show the message once.
        let g:diff_msg_shown = 1
    endif


I really like diff mode, but I do not use it routinely, so I often forget
the commands.  So this will show me the commands when I launch it.  I just
have to press <enter> through the prompt.

As per the comments, my Nodiff looks like this:
" Courtesy of Gary Johnson
if v:version >= 602
    command! -bar Nodiff wincmd l <bar> only <bar> set nodiff noscrollbind
scrollopt-=hor wrap foldcolumn=0 virtualedit= columns=80 <bar> let
g:diff_msg_shown = 0
else
    command! -bar Nodiff exe 'wincmd l' <bar> only <bar> set nodiff
noscrollbind wrap foldcolumn=0 scrollopt-=hor virtualedit= <bar> let
g:diff_msg_shown = 0
endif



I launch it in 2 ways:
1.  Either edit the first file, then type:
:vert diffsplit <other filename>

2.  From the command line:
gvim -O -d two files

Since I use vert diffsplit, my MyDiff function also does this:
    let &columns=166

Which essentially maximizes the display so I can see both files pretty well
while diffing.
Note the Nodiff command puts columns back to 80.

HTH,
Dave

--
Do you use Vim to edit SQL?
<Plug>
Check the description of these plugins:
dbext.vim - Provides database access to 10 databases (Oracle, Sybase, SQL
Server, MySQL,...) (http://www.vim.org/scripts/script.php?script_id=356)
SQLUtilities - Formatting SQL, generate - columns lists, procedures for
databases (http://www.vim.org/scripts/script.php?script_id=492)
sql.vim - SQL indent file for Sybase ASA and Oracle
(http://www.vim.org/scripts/script.php?script_id=495)
Intellisense for Vim : SQL, C++, CSharp, Java, JSP, XML, HTML
(http://www.vim.org/scripts/script.php?script_id=747)
</Plug>


Reply | Threaded
Open this post in threaded view
|

Re: vimdiff usage

Peter Bismuti
In reply to this post by Mark Volkmann-2
xxdiff is the superior diff tool, thought you might want to know.
----- Original Message -----
From: "Mark Volkmann" <[hidden email]>
To: <[hidden email]>
Sent: Friday, September 30, 2005 3:39 PM
Subject: vimdiff usage


I'm just learning how to use vimdiff to find the difference between
two files. I know there are many ways to start it. I'm interested in
using it after I already have vim running. Here's what I did.

- open first file
- ":sp" to split the window
- open second file in second window
- ":diffthis" in both buffers
- "]c" to move to next difference
- "[c" to move to previous difference

That seemed to work fine. Then I wanted to turn it off, so I did this.

- ":set nodiff" in both buffers
- ":set noscrollbind" in both buffers

Is there an easier way to set it up or turn it off?

--
R. Mark Volkmann
Partner, Object Computing, Inc.