Changes you just edited [buffer], i.e. those that differ from last saved version (in working directory), these may differ with last index version (Git). I mapped both:
" Find diff inbetween currrent buffer and ... A{last index version} vs B{last saved version in working directory}
" - A{last index version}: the file as you last commited it
" git diff to vimdiff against the index version of the file:
nnoremap <leader>gd <Esc>:Gvdiff<CR><Esc>:echo "currentBuffer vs lastIndexVersion (last commited)"<CR>
" - B{last saved version in working directory}: the file you last :w,
" not neccesary commited it (not commited for sure if it is in NO git project)
" https://vim.fandom.com/wiki/Diff_current_buffer_and_the_original_file
nnoremap <leader>gd2 <Esc>:DiffSaved<CR><Esc>:echo "currentBuffer vs lastSaved (not neccesary equal to last commited)"<CR>
function! s:DiffWithSaved()
let filetype=&ft
diffthis
vnew | r # | normal! 1Gdd
diffthis
exe "setlocal bt=nofile bh=wipe nobl noswf ro ft=" . filetype
endfunction
com! DiffSaved call s:DiffWithSaved()
Example of vimdiff vs Gdiff.
- vimdiff:
- Gdiff: Commiting changes, you see only Gdiff, what might, or might have same changes as vimdiff:
Furthermore, to easy vimdiff
homonym file in other path:
" vimdiff homonym file
nnoremap <leader>dh <Esc>:vsplit %:p:h/../__/%:t <bar> :windo diffthis<Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left>
"E.g."$ vim /path01/proj02_pg064/processorder.php
":vsplit %:p:h/../proj01_pg05/%:t | :windo diffthis