如何退出vim中的vimdiff模式,特别是逃犯?
我正在使用vim和逃犯扩展 。 它有一个:Gdiff命令,它将你带入vimdiff模式,但closures/退出vimdiff模式的方法是什么?
也就是说,我正在编辑Git存储库下的文件FooBar.txt。 我启动了:Gdiff,检查vimdiff中的更改,然后我想返回并继续编辑FooBar.txt或任何其他文件:)
UPDATE1:我打算在下一个工作日试试这些快速连击:)
"vimdiff current vs git head (fugitive extension) nnoremap <Leader>gd :Gdiff<cr> "switch back to current file and closes fugitive buffer nnoremap <Leader>gD :diffoff!<cr><cw>h:bd<cr> UPDATE2:我目前的映射(只closures差异窗口!)
 "vimdiff current vs git head (fugitive extension) nnoremap <Leader>gd :Gdiff<cr> "switch back to current file and closes fugitive buffer nnoremap <Leader>gD <cw>h<cw>c 
另外,请帮助我决定是否应该是一个安装程序: https ://stackoverflow.com/a/15975201/275980
 你可以执行windo set nodiff noscrollbind ,然后closures第二个窗口。 
 更新:有一个diffoff命令。 使用windo diffoff ,而不是我在前一行中写的。 
根据: https : //github.com/tpope/vim-fugitive/issues/36
closures另一个窗口。 如果您没有将焦点移到焦点上,则最简单的方法是
<CW><CO>,这意味着“使此窗口成为唯一窗口”。
 我没有diffoff运气,但我刚刚了解到:Gedit diffoff没有参数将带你回到文件的工作目录版本,而不是你正在审查的一些早期的版本。 
 而q (不需要:q )会closuresdiff侧边栏,你可以先执行q后面的:Gedit来摆脱边栏,然后回到当前版本的文件。 
这对我来说很好,结合了一些现有的想法:
 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> 
我find了一个简单的解决scheme。 你可以在这里查看: 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 
上述解决scheme都不适合我。 结束了这个,而不是:
 nnoremap <Leader>D :Gedit<CR><Cw>h :q<CR><Cw>k 
 如果您有多个窗口,则<CW><CO>的替代方法将移至另一个窗口并执行<CW>c ,该窗口只closures一个窗口。 
 如果你closures错误的差异窗口做一个:Gedit 
 小心,不要把<CW>c和<CW><CC>混淆 
这是使用后我必须离开vimdiff窗口:Gdiff
 nnoremap gD :q!<CR> :Gedit!<CR> 
 noremap <leader>do :diffoff \| windo if &diff \| hide \| endif<cr> 
相当差异模式,并closures其他差异窗口。 (注:逃犯会自动删除其隐藏的缓冲区。)
 我的function将从差异窗口和文件窗口。 但可能不会处理打开多个差异。 为此,您需要使用fugitive#buffer(n).path()来扫描和匹配。 
 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 
添加一个键绑定:
 nnoremap <silent> <leader>gD :Gdiffoff<CR> 
另一种方式。 我在fugitive.vim中有什么 – 首先在diff开始时保存一些信息(s:gitbufname):
 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."\<CW>w", 'n') endif ... endfunction 
以后在将缓冲区切换窗口保存到保存的缓冲区时恢复:
 augroup fugitive_diff autocmd! autocmd BufWinLeave * \ if s:can_diffoff(+expand('<abuf>')) && 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('<abuf>'), 'git_dir')) | \ call sy#toggle() | \ call airline#load_theme() | call airline#update_statusline() | \ let &columns=s:startcol | \ endif ... 
 检查vimdiff 在这个页面的 diffthis和diffoff之间切换。 
代码:
 nnoremap <silent> <Leader>df :call DiffToggle()<CR> function! DiffToggle() if &diff diffoff else diffthis endif :endfunction 
方法1:
- 打开一个比较:
 :windo diffthis 
- closures它:
 :windo diffoff 
方法2:
 我build议使用最简单的命令:q<CR> 
当你想快速做到这一点,添加映射:
 " Set mapleader let mapleader = "," let g:mapleader = "," 
和
 " Quickly close the current window nnoremap <leader>q :q<CR> 
 这对我来说很有用。 只需通过,q退出vimdiff,因为通常您的光标位于旧文件中。