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"
  • Related SO post about using tabs as buffers: Using Vim's tabs like buffers Commented Mar 8, 2018 at 15:31
  • I found this question because I didn't want the workspace loaded by vim-workspace when VIm was executed by git difftool but in this case let g:workspace_session_disable_on_args = 1 suits me better. Commented Dec 11, 2019 at 13:50

2 Answers 2


: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
      setup for non-diff mode

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

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

See :h 'diff'

  • Snap! I'll upvote yours if you upvote mine ;)
    – Rich
    Commented Mar 8, 2018 at 12:15
  • Ahah I was 6 seconds too slow to click "submit"! Have my upvote :)
    – statox
    Commented Mar 8, 2018 at 12:16
  • Thanks for the quick respone! Wondering if there is an option to identify view & vi too?
    – Ankit Jain
    Commented Mar 8, 2018 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
    Commented Mar 8, 2018 at 12:25
  • 3
    @AnkitJain :h v:progname Commented Mar 8, 2018 at 13:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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