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

后端 未结 15 1867
日久生厌
日久生厌 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:39

    noremap <leader>do :diffoff \| windo if &diff \| hide \| endif<cr>

    Quite diff mode and close other diff windows. (Note: fugitive will auto delete its hidden buffers.)

    0 讨论(0)
  • 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 <Leader>gD :call MyCloseDiff()<cr>
    
    0 讨论(0)
  • 2021-01-30 05:42

    Check the vimdiff toggling between diffthis and diffoff here at this page.

    The code:

    nnoremap <silent> <Leader>df :call DiffToggle()<CR>
    
    function! DiffToggle()
        if &diff
            diffoff
        else
            diffthis
        endif
    :endfunction
    
    0 讨论(0)
  • 2021-01-30 05:42

    Method 1:

    • open a compare by:

    :windo diffthis

    • close it by:

    :windo diffoff

    Method 2:

    I recommend just using the most simple command: :q<CR>

    when you want to do it quickly, add the mapping:

    " Set mapleader
    let mapleader = ","
    let g:mapleader = ","
    

    and

    " Quickly close the current window
    nnoremap <leader>q :q<CR>
    

    It works well for me. Exit vimdiff just by ,q, because normally your cursor in the old file.

    0 讨论(0)
  • 2021-01-30 05:43

    You can execute windo set nodiff noscrollbind and then close the second window.

    Update: there is a diffoff command. Use windo diffoff, not what I wrote in previous line.

    0 讨论(0)
  • 2021-01-30 05:45

    this is what I have to leave the vimdiff windows after using :Gdiff

    nnoremap gD :q!<CR> :Gedit!<CR>
    
    0 讨论(0)
提交回复
热议问题