existance of :diffoff

14 views
Skip to first unread message

Bee

unread,
Apr 19, 2012, 1:57:41 AM4/19/12
to vim_use
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! ?

And is this function sufficient?

Bill

Jürgen Krämer

unread,
Apr 19, 2012, 2:13:53 AM4/19/12
to vim...@googlegroups.com

Hi,

Bee schrieb:


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

:echo exists(':diffoff')

> And is this function sufficient?

Additionally check if the window is really in diff mode:

function! DiffOff()
if exists(':diffoff') == 2
windo if &diff | set nodiff foldcolumn=0 noscrollbind nowrap scrollopt-=hor | endif


else
diffoff!
endif
close
endf

Regards,
J�rgen

--
Sometimes I think the surest sign that intelligent life exists elsewhere
in the universe is that none of it has tried to contact us. (Calvin)

Bee

unread,
Apr 19, 2012, 2:37:24 AM4/19/12
to vim_use
Thank you Jürgen

I think it better to place the test for &diff first:

function! DiffOff()
if &diff
if exists(':diffoff') == 2
windo set nodiff foldcolumn=0 noscrollbind nowrap scrollopt-
=hor
else
diffoff!
endif
close
endif
endf

Gary Johnson

unread,
Apr 19, 2012, 2:41:46 AM4/19/12
to vim_use
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

Gary Johnson

unread,
Apr 19, 2012, 2:52:59 AM4/19/12
to vim_use
On 2012-04-18, Gary Johnson wrote:
> 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")
> ...

As J�rgen wrote, that should be

if exists(":diffoff") == 2

there and in my example.

Regards,
Gary

Jürgen Krämer

unread,
Apr 19, 2012, 3:24:44 AM4/19/12
to vim...@googlegroups.com

Hi,

Bee wrote:


>
>
> On Apr 18, 11:13 pm, J�rgen Kr�mer <jottka...@googlemail.com> wrote:
>>
>> Additionally check if the window is really in diff mode:
>>
>> function! DiffOff()
>> if exists(':diffoff') == 2
>> windo if &diff | set nodiff foldcolumn=0 noscrollbind nowrap scrollopt-=hor | endif
>> else
>> diffoff!
>> endif
>> close
>> endf
>

> Thank you J�rgen


>
> I think it better to place the test for &diff first:
>
> function! DiffOff()
> if &diff
> if exists(':diffoff') == 2

> windo set nodiff foldcolumn=0 noscrollbind nowrap scrollopt-=hor
> else
> diffoff!
> endif
> close

> endif
> endf

no, better keep it inside the windo command. Your modified version would
only work if you are currently in a window that actually is in diff mode,
while the built-in :diffoff! also works when called from a window that is
not in diff mode. That's because 'diff' is a window-local option.

Reply all
Reply to author
Forward
0 new messages