how you usually quiting/closing vimdiff mode?

4,099 views
Skip to first unread message

wik

unread,
Apr 24, 2010, 3:47:34 AM4/24/10
to vim_use
Hello,

I am using vim with fugitive extension http://www.vim.org/scripts/script.php?script_id=2975
It has :Gdiff command which brings you into vimdiff mode, but what is
the right/quick way to close/quit vimdiff mode?

i.e. let's say I am editing file FooBar.txt under git repository, then
firing up :Gdiff, review my changes in vimdiff and want to get back
and continue editing FooBar.txt or any other file :)

Thanks.

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

Subscription settings: http://groups.google.com/group/vim_use/subscribe?hl=en

Tony Mechelynck

unread,
Apr 24, 2010, 4:38:05 AM4/24/10
to vim...@googlegroups.com, wik
On 24/04/10 09:47, wik wrote:
> Hello,
>
> I am using vim with fugitive extension http://www.vim.org/scripts/script.php?script_id=2975
> It has :Gdiff command which brings you into vimdiff mode, but what is
> the right/quick way to close/quit vimdiff mode?
>
> i.e. let's say I am editing file FooBar.txt under git repository, then
> firing up :Gdiff, review my changes in vimdiff and want to get back
> and continue editing FooBar.txt or any other file :)
>
> Thanks.
>

See :help diff.txt

:diffoff!

then in the split-windows which you don't want to stay open:

:q

Particular case: To stop diff mode by quitting Vim, just

:qa

(or :xa if there are 'modified' files which you want to save before
quitting) is usually enough.

Other ways to _start_ diff mode:

[g]vimdiff file1 file2

(in the shell) or _one_ of the ex-commands

:DiffOrig
:diffsplit filename.ext
:diffthis

in Vim. They all have help; :DiffOrig is defined in vimrc_example.vim,
or you can copy its code from the help topic; :diffthis has to be
repeated in each of the split-windows which you want to make part of the
diff.


Best regards,
Tony.
--
Canada Post doesn't really charge 32 cents for a stamp. It's 2 cents
for postage and 30 cents for storage.
-- Gerald Regan, Cabinet Minister, 12/31/83 Financial
Post

Vladimir Rybas

unread,
Apr 24, 2010, 6:27:23 AM4/24/10
to vim...@googlegroups.com, wik
:windo diffthis to see diffs between files in splits. 
:windo diffoff when you're done

Tim Chase

unread,
Apr 24, 2010, 7:02:39 AM4/24/10
to vim...@googlegroups.com, Tony Mechelynck, wik
On 04/24/2010 03:38 AM, Tony Mechelynck wrote:
> On 24/04/10 09:47, wik wrote:
>> what is the right/quick way to close/quit vimdiff mode?
>>
>> i.e. let's say I am editing file FooBar.txt under git
>> repository, then firing up :Gdiff, review my changes in
>> vimdiff and want to get back and continue editing FooBar.txt
>> or any other file :)
>
> :diffoff!

Nice...I hadn't learned about the "!" until now. I resorted to

:windo diffoff

One more good trick to add to my bag.

> then in the split-windows which you don't want to stay open:
>
> :q

Or alternatively, if you're in the window you want to keep, you
can either use

:on

or control-W followed by "o"

:help :only
:help CTRL-w_o

If you want to close despite changes in the windows you're
closing, you can use

:on!

however this means they're 'hidden', so you still have to deal
with them upon quitting, either writing, or issuing a ":qa!".
AFAICT, there is no in-built variant of ":only" that behaves like
"q!" in each non-focused window in the current tab. I wrote a
short ":On" command once to do that but just found I didn't use
it, so I abandoned it.

-tim

Christian Brabandt

unread,
Apr 24, 2010, 7:10:46 AM4/24/10
to vim...@googlegroups.com
Hi Tony!

On Sa, 24 Apr 2010, Tony Mechelynck wrote:

> On 24/04/10 09:47, wik wrote:
>> i.e. let's say I am editing file FooBar.txt under git repository, then
>> firing up :Gdiff, review my changes in vimdiff and want to get back
>> and continue editing FooBar.txt or any other file :)
>
> See :help diff.txt
>
> :diffoff!
>

Am I the only one who finds it annoying, that diffoff resets the
settings foldcolumn, foldmethod, and wrap among others? (I don't care
for 'scrollbind' and 'scrollopt' and 'diff' probably makes sense to
reset)

regards,
Christian

Gary Johnson

unread,
Apr 24, 2010, 3:49:44 PM4/24/10
to vim...@googlegroups.com
On 2010-04-24, Christian Brabandt wrote:
> Hi Tony!
>
> On Sa, 24 Apr 2010, Tony Mechelynck wrote:
>
> > On 24/04/10 09:47, wik wrote:
> >> i.e. let's say I am editing file FooBar.txt under git repository, then
> >> firing up :Gdiff, review my changes in vimdiff and want to get back
> >> and continue editing FooBar.txt or any other file :)
> >
> > See :help diff.txt
> >
> > :diffoff!
> >
>
> Am I the only one who finds it annoying, that diffoff resets the
> settings foldcolumn, foldmethod, and wrap among others? (I don't care
> for 'scrollbind' and 'scrollopt' and 'diff' probably makes sense to
> reset)

FWIW, I wrote the following before the :diffoff command was
introduced, so it could probably be improved, but I use it to get
out of diff mode and back to the state Vim was in before I executed
a :diff* command. It makes some assumptions about the way I use
diff, e.g., always in a vertically-split window.

Each command definition is one horrendously long line.

"Nodiff" assumes I started with one window and executes ":only".
"Undiff" keeps all windows; it just turns off diff. The names could
be better and yes, I have confused the two.

--------------------------------------------------------------------

command! -bar -bang Nodiff wincmd l <bar> only<bang> <bar> set nodiff noscrollbind scrollopt-=hor wrap foldcolumn=0 virtualedit= foldlevel=99 <bar> if exists("b:fdm") <bar> let &fdm = b:fdm <bar> endif <bar> if exists("b:syn") <bar> let &syn = b:syn <bar> endif

command! -bar -bang Undiff let wn=winnr() <bar> windo set nodiff noscrollbind scrollopt-=hor wrap foldcolumn=0 virtualedit= foldlevel=99 <bar> windo exe 'if exists("b:fdm") <bar> let &fdm = b:fdm <bar> endif' <bar> windo exe 'if exists("b:syn") <bar> let &syn = b:syn <bar> endif' <bar> exe wn . 'wincmd w'

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

" Remember the current 'foldmethod' so that it can be restored after a
" diff by the Nodiff or Undiff command.
"
au BufWinEnter * if &fdm != "diff" | let b:fdm = &fdm | endif

" Turn off syntax highlighting for diff'd buffers.
"
au FilterWritePre * exe 'let b:syn = &syn | if &diff | set syn=OFF | endif'

--------------------------------------------------------------------

Regards,
Gary

wik

unread,
Apr 25, 2010, 9:26:08 AM4/25/10
to vim_use
Hello guys,

thank you so much for the answers, here is quick combos I'm going to
give a try next working days :)

nnoremap <Leader>gd :Gdiff<cr> " open vimdiff for current file and git
head (fugitive extension)
nnoremap <Leader>gD :diffoff!<cr><c-w>h:bd<cr> " switch back to
current file and closes fugitive buffer

Ben Fritz

unread,
Apr 26, 2010, 11:14:07 AM4/26/10
to vim_use


On Apr 24, 6:10 am, Christian Brabandt <cbli...@256bit.org> wrote:
>
> Am I the only one who finds it annoying, that diffoff resets the
> settings foldcolumn, foldmethod, and wrap among others? (I don't care
> for 'scrollbind' and 'scrollopt' and 'diff' probably makes sense to
> reset)
>

I find this very annoying. Annoying enough, in fact, that I usually
launch diff like this if I already have the buffer for file1 open for
editing:

:tab sp
:diffsp file2

Then when I'm done I can (usually) just do a :tabclose to quit the
diff and go back to editing without problems.
Reply all
Reply to author
Forward
0 new messages