Wednesday, April 18, 2012

Re: existance of :diffoff

On 2012-04-18, Bee wrote:
> I use vim on Mac, Linux, Windows with versions 6 and 7.
>
> :diffoff! works with version 7 but does not exist in version 6.
>
> Currently I do this:
>
> function! DiffOff()
> if v:version < 700
> windo set nodiff foldcolumn=0 noscrollbind nowrap scrollopt-=hor
> else
> diffoff!
> endif
> close
> endf
>
> Is there a way to specifically check for the existence of :diffoff! ?

if exists(":diffoff")
...

See

:help exists()

> And is this function sufficient?

I think so, except that I think your "nowrap" should be "wrap". I
use this:

if exists(":diffoff")
command! -bar -bang Nodiff wincmd l
\ <bar> only<bang>
\ <bar> diffoff
\ <bar> set virtualedit= foldlevel=99
\ <bar> if exists("b:fdm")
\ <bar> let &fdm = b:fdm
\ <bar> endif
\ <bar> if exists("b:syn")
\ <bar> let &l:syn = b:syn
\ <bar> endif
command! -bar -bang Undiff let wn=winnr()
\ <bar> diffoff!
\ <bar> windo set 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 &l:syn = b:syn <bar> endif'
\ <bar> exe wn . 'wincmd w'
else
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 &l: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 &l:syn = b:syn <bar> endif'
\ <bar> exe wn . 'wincmd w'
endif

because I save and restore the foldmethod and syntax state when I
enter and leave diff mode, and also use virualedit=all when in diff
mode. If you strip all my extra stuff away, our solutions are very
similar. Nodiff assumes that there are only two windows, closes the
left window, then turns off diff mode in the remaining window.
Undiff turns off diff mode in all windows.

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

No comments: