8

I have a function in vim which will open all buffers as tabs. However after I add this function, vimdiff too opens the files to be compared as different tabs and hence doesn't show the differences. Is there a way where I can find out if its vim or vimdiff which is invoking my vimrc file?

function! OpenTabs()
    let bf=len(filter(range(1, bufnr('$')), 'buflisted(v:val)'))
    if bf > 1
      exe "tab 5sball"
    endif
endfunction
11

:help diff covers this:

In your .vimrc file you could do something special when Vim was started in diff mode. You could use a construct like this:

   if &diff
      setup for diff mode
   else
      setup for non-diff mode
   endif
10

You can use the &diff option like in your vimrc:

if &diff
    echo "in diff mode"
else
    echo "not in diff mode"
endif

See :h 'diff'

  • Snap! I'll upvote yours if you upvote mine ;) – Rich Mar 8 '18 at 12:15
  • Ahah I was 6 seconds too slow to click "submit"! Have my upvote :) – statox Mar 8 '18 at 12:16
  • Thanks for the quick respone! Wondering if there is an option to identify view & vi too? – Ankit Jain Mar 8 '18 at 12:17
  • @AnkitJain For the view you might check if all of your buffers have the 'readonly' option set, or maybe you can alias view to set a vim variable that you would check on startup. – statox Mar 8 '18 at 12:25
  • 3
    @AnkitJain :h v:progname – Christian Brabandt Mar 8 '18 at 13:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.