Skip to content

Instantly share code, notes, and snippets.

@romainl
Created August 13, 2016 12:24
Show Gist options
  • Save romainl/481814c86dba39d32715ff77ec96c1ed to your computer and use it in GitHub Desktop.
Save romainl/481814c86dba39d32715ff77ec96c1ed to your computer and use it in GitHub Desktop.
Diff detection in vimscript
" this should echo '1' when entering 'diff mode' and '0' otherwise
function! IsDiff(opt)
let isdiff = 0
if v:progname =~ "diff"
let isdiff = isdiff + 1
endif
if &diff == 1
let isdiff = isdiff + 1
endif
if a:opt =~ "scrollopt"
if &scrollopt =~ "hor"
let isdiff = isdiff + 1
endif
endif
return isdiff
endfunction
autocmd! VimEnter,OptionSet * echom IsDiff(expand('<amatch>'))
@romainl
Copy link
Author

romainl commented Jan 26, 2022

:help v:argv should help, nowadays.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment