Saturday, April 24, 2010

Re: how you usually quiting/closing vimdiff mode?

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

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

No comments:

Post a Comment