I use the solution provided here, reproduced below:
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()
to visually diff a buffer I am currently working on with the saved version on disk. Suppose my buffer list contains one file, file1.cpp
(this is the only file that appears on :ls
). Suppose I modify this buffer and obtain file1.cpp+
. +
here indicates that the buffer contents have diverged from the version saved on disk. On calling :DiffSaved
, the output of :DiffSaved
appears on the full screen where the screen is split so (x is the cursor position):
________________
.cpp | .cpp+ |
| |
x | |
_______|________|
That is, the file on disk appears on left where the cursor is.
On this new tab(?), if I run :ls
, I still see only file.cpp+
. Aren't the two windows of the output of DiffSaved
also part of the buffer list? Is the output of DiffSaved
on some temporary space elsewhere? Is it possible to have the output so where the current file's buffer appears on the left so that a :w
saves the file if I am satisfied with the diff? As of now, to save the buffer, either I have to close this diff tab via :q
and issue a :w
on the underlying file buffer. Or else, one has to navigate right to the modified buffer in the diff output tab and write buffer to file.
Preferred diff output layout
________________
.cpp+ | .cpp |
| |
x | |
_______|________|