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 Mar 8 '18 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. Dec 11 '19 at 13:50

: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
    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 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.