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

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

    According to: https://github.com/tpope/vim-fugitive/issues/36

    Close the other window. The easiest way to do this if you haven't shifted focus to it is <C-W><C-O>, which means "make this Window the Only window."

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

    My function will work both from diff window and file window. But probably won't handle itself with multiple diffs opened. For that you'll need to use fugitive#buffer(n).path() to scan and match.

    command! Gdiffoff call Gdiffoff()
    function! Gdiffoff()
        let diffbufnr = bufnr('^fugitive:')
        if diffbufnr > -1 && &diff
            diffoff | q
            if bufnr('%') == diffbufnr | Gedit | endif
            setlocal nocursorbind
        else
            echo 'Error: Not in diff or file'
        endif
    endfunction
    

    Add a key binding:

    nnoremap <silent> <leader>gD :Gdiffoff<CR>
    
    0 讨论(0)
  • 2021-01-30 05:28

    I had no luck with diffoff, but I just learned that :Gedit with no argument will bring you back to the working-directory version of the file, as opposed to some earlier version you were reviewing.

    And as q (no need for :q) will close the diff sidebar, you can do q followed by :Gedit to get rid of the sidebar and then go back to the current version of the file.

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

    I've found a simple solution for this. You can check it here: https://gist.github.com/radmen/5048080

    " Simple way to turn off Gdiff splitscreen
    " works only when diff buffer is focused
    if !exists(":Gdiffoff")
      command Gdiffoff diffoff | q | Gedit
    endif
    
    0 讨论(0)
  • 2021-01-30 05:32

    None of the above solutions worked for me. Ended up doing this instead:

    nnoremap <Leader>D :Gedit<CR><C-w>h :q<CR><C-w>k

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

    Running :Gwrite after merging to your satisfaction will close the other two diff panes in addition to updating the git cache to mark the file as merged.

    0 讨论(0)
提交回复
热议问题