Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Taking a quick look at DiffOrig, then switching back

Tags:

vim

editor

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 :-)

like image 442
Flavius Avatar asked Jun 21 '11 13:06

Flavius


1 Answers

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>
like image 129
dahu Avatar answered Oct 19 '22 03:10

dahu