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

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

    Yet another way. What I have in fugitive.vim - first save some info (s:gitbufname) when diff starts:

    function! s:Diff(vert,...) abort
      call sy#toggle()
      let s:startcol = winwidth(0)
      let &columns=(winwidth(0) * 2 - 20)
    ...
        if getwinvar('#', '&diff')
          let s:gitbufname = bufname("%")
          wincmd p
          call feedkeys(winnr."\w", 'n')
        endif
    ...
    endfunction
    

    and later when leaving the buffer switch window to the saved buffer and restore:

    augroup fugitive_diff
    autocmd!
    autocmd BufWinLeave *
      \ if s:can_diffoff(+expand('')) && s:diff_window_count() == 2 |
      \   if exists('s:gitbufname') && winnr() != bufwinnr(s:gitbufname) |
      \     let nr = bufnr("%") | exe bufwinnr(s:gitbufname).'wincmd w' | exe 'buf'.nr |
      \   endif |
      \   call s:diffoff_all(getbufvar(+expand(''), 'git_dir')) |
      \   call sy#toggle() |
      \   call airline#load_theme() | call airline#update_statusline() |
      \   let &columns=s:startcol |
      \ endif
    ...
    

提交回复
热议问题