I am trying to find (in Vim script) if the 2 files open using vimdiff are same or different? Is there a way to do that? (a variable like &diff perhaps?)
The easiest option is not to make vim do any work at all:
diff -q reports if files are different, and
diff -s if they are the same. According to this answer if you don’t need output,
cmp -s works.
So in vimscript you might do
let l:files = [ get_file_names() ] " left as an exercise call system('cmp -s ' . join(l:files, ' ')) " do something with v:shell_error
Okay, this is a very hacky approach. You really should check the result of
diff using e.g. a custom
diffexpr. But you asked for it, so here we go:
let a=win_getid()|exe "windo let g:diff=(get(g:, 'diff', 1) && foldclosed(1) && foldclosedend(1)==line('$'))"|if g:diff |echomsg 'no differences found' |else |echomsg 'there are some differences!' |endif|call win_gotoid(a)
This assumes, that all windows are in diff mode and basically checks, whether each window contains only a single folded line.