How do you exit vimdiff mode in vim, specifically, for Fugitive?

后端 未结 15 1875
日久生厌
日久生厌 2021-01-30 05:01

I am using vim with the fugitive extension. It has a :Gdiff command which brings you into vimdiff mode, but what is the right/quick way to close/quit vimdiff mode?

I.e.,

15条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-30 05:41

    This works fine for me, combining some of the existing ideas here:

    function! MyCloseDiff()
      if (&diff == 0 || getbufvar('#', '&diff') == 0)
            \ && (bufname('%') !~ '^fugitive:' && bufname('#') !~ '^fugitive:')
        echom "Not in diff view."
        return
      endif
    
      " close current buffer if alternate is not fugitive but current one is
      if bufname('#') !~ '^fugitive:' && bufname('%') =~ '^fugitive:'
        if bufwinnr("#") == -1
          b #
          bd #
        else
          bd
        endif
      else
        bd #
      endif
    endfunction
    nnoremap gD :call MyCloseDiff()
    

提交回复
热议问题