问题
I've discovered this great command from the documentation:
command DiffOrig vert new | set bt=nofile | r # | 0d_ | diffthis
\ | wincmd p | diffthis
So I've come up with this:
command DiffOrig vert new | set bt=nofile | r # | 0d_ | diffthis | wincmd p | diffthis | wincmd p
map <Leader>do :DiffOrig<cr>
map <leader>dc :q<cr>:diffoff!<cr>
The problem is, when I se \dc, it will jump back to the beginning of the file, not where I left it prior to issuing \do. How to fix this?
Please try this yourself, see what the problems are and how to fix them. And tell me how to fix them too :-)
回答1:
You could try:
command DiffOrig let g:diffline = line('.') | vert new | set bt=nofile | r # | 0d_ | diffthis | :exe "norm! ".g:diffline."G" | wincmd p | diffthis | wincmd p
nnoremap <Leader>do :DiffOrig<cr>
nnoremap <leader>dc :q<cr>:diffoff<cr>:exe "norm! ".g:diffline."G"<cr>
回答2:
You can :q in the window you want to close, and then :diffoff to turn off the diff formatting in the remaining window. Not sure if it can be done in one command.
回答3:
To close the diff windows and go back to the file you were editing, you could try adding this to your .vimrc file:
if !exists(":DiffOff")
command DiffOff diffoff <bar> only
endif
Then enter :DiffOff to close the diff windows.
来源:https://stackoverflow.com/questions/6426154/taking-a-quick-look-at-difforig-then-switching-back