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

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

    Was using the code below based on https://stackoverflow.com/a/15113951/10999673 :

        if !exists(":Gdiffoff")
            command Gdiffoff bw! fugitive://*
        endif
    

    but it gave me an error "E93: more than one match for ..." in a 3 way diff, so i instead used the answer from https://stackoverflow.com/a/4867969/10999673 and finally have this:

    function! GetBufferList()
        return filter(range(1,bufnr('$')), 'buflisted(v:val)')
    endfunction
    
    function! GetMatchingBuffers(pattern)
        return filter(GetBufferList(), 'bufname(v:val) =~ a:pattern')
    endfunction
    
    function! WipeMatchingBuffers(pattern)
        let l:matchList = GetMatchingBuffers(a:pattern)
    
        let l:count = len(l:matchList)
        if l:count < 1
            echo 'No buffers found matching pattern ' . a:pattern
            return
        endif
    
        if l:count == 1
            let l:suffix = ''
        else
            let l:suffix = 's'
        endif
    
        exec 'bw ' . join(l:matchList, ' ')
    
        echo 'Wiped ' . l:count . ' buffer' . l:suffix . '.'
    endfunction
    
    command! -nargs=1 Gdiffoff call WipeMatchingBuffers('fugitive://')
    
    

    I just tweaked, copied and pasted the code into my .vimrc

提交回复
热议问题