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

后端 未结 15 1898
日久生厌
日久生厌 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: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  gD :Gdiffoff
    

提交回复
热议问题