Taking a quick look at DiffOrig, then switching back

不羁岁月 提交于 2020-01-02 02:00:15

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!