From 299193edc0710314599d24a6e14a08df8832e423 Mon Sep 17 00:00:00 2001 From: Charalampos Kardaris Date: Mon, 17 Nov 2025 17:58:24 +0100 Subject: [PATCH 1/3] Suppress Netrw unlisted buffer deletion error The Netrw plugin creates an 'unlisted' buffer for directories. Running 'bd {buffer}' on an unlisted buffer produces the following error: E516: No buffers were deleted. Suppress the error with 'silent!'. --- plugin/dirdiff.vim | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/plugin/dirdiff.vim b/plugin/dirdiff.vim index 2389f7a..9ab541a 100644 --- a/plugin/dirdiff.vim +++ b/plugin/dirdiff.vim @@ -511,7 +511,11 @@ function! DirDiffOpen() let previousFile = (s:LastMode == "A") ? previousFileA : previousFileB call Drop(previousFile) silent exec "edit ".fileToOpen - silent exec "bd ".bufnr(previousFile) + " The Netrw plugin creates an 'unlisted' buffer for directories. + " Running 'bd {buffer}' on an unlisted buffer produces the following error: + " E516: No buffers were deleted. + " Suppress the error with 'silent!'. + silent! exec "bd ".bufnr(previousFile) endif else silent exec "split ".fileToOpen @@ -541,7 +545,11 @@ function! DirDiffOpen() let previousFile = (s:LastMode == "A") ? previousFileA : previousFileB call Drop(previousFile) silent exec "edit ".s:FilenameB - silent exec "bd ".bufnr(previousFile) + " The Netrw plugin creates an 'unlisted' buffer for directories. + " Running 'bd {buffer}' on an unlisted buffer produces the following error: + " E516: No buffers were deleted. + " Suppress the error with 'silent!'. + silent! exec "bd ".bufnr(previousFile) diffthis " To ensure that A is on the left and B on the right, splitright must be off From 1f946cbf718b2db4e0de38108aab80fb6b5e2b45 Mon Sep 17 00:00:00 2001 From: Charalampos Kardaris Date: Mon, 17 Nov 2025 17:58:24 +0100 Subject: [PATCH 2/3] Fix window navigation if 'splitbelow' is set Do not rely on 'wincmd h/j/k/l' movements, because the 'splitbelow' options affects the position of the diff window. --- plugin/dirdiff.vim | 38 ++++++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/plugin/dirdiff.vim b/plugin/dirdiff.vim index 9ab541a..affabd8 100644 --- a/plugin/dirdiff.vim +++ b/plugin/dirdiff.vim @@ -414,21 +414,31 @@ function ToggleHex() endfunction function! DirDiffHexmode() - wincmd k - call ToggleHex() - wincmd l - call ToggleHex() + " Support hex mode only for existing files (not directories). + if filereadable(s:FilenameA) + call GotoFileAWindow() + call ToggleHex() + endif + if filereadable(s:FilenameB) + call GotoFileBWindow() + call ToggleHex() + endif " Go back to the diff window - wincmd j + call GotoDiffWindow() endfunction function! DirDiffWrapmode() - wincmd k - setlocal wrap! - wincmd l - setlocal wrap! + " Support wrap mode only for existing files (not directories). + if filereadable(s:FilenameA) + call GotoFileAWindow() + setlocal wrap! + endif + if filereadable(s:FilenameB) + call GotoFileBWindow() + setlocal wrap! + endif " Go back to the diff window - wincmd j + call GotoDiffWindow() endfunction function! EscapeFileName(path) @@ -459,6 +469,14 @@ function! Drop(fname) endif endfunction +function! GotoFileAWindow() + call Drop(s:FilenameA) +endfunction + +function! GotoFileBWindow() + call Drop(s:FilenameB) +endfunction + function! GotoDiffWindow() call Drop(s:FilenameDiffWindow) endfunction From ec67602a5bfc4413be7b55c28b3d0b2ec054e701 Mon Sep 17 00:00:00 2001 From: Charalampos Kardaris Date: Mon, 17 Nov 2025 17:58:24 +0100 Subject: [PATCH 3/3] Fix Netrw window focus when g:netrw_liststyle = 3 If the Netrw plugin is configured in tree style listing mode (i.e. g:netrw_liststyle = 3), then a buffer named 'NetrwTreeListing' is shown (i.e. active window). This happens only after the original buffer, which has the directory as its name, is focused for the first time. We work around this by comparing the 'netrw_curdir' variable of the 'NetrwTreeListing' buffer against the directory name. --- plugin/dirdiff.vim | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/plugin/dirdiff.vim b/plugin/dirdiff.vim index affabd8..ea139ab 100644 --- a/plugin/dirdiff.vim +++ b/plugin/dirdiff.vim @@ -465,7 +465,19 @@ function! Drop(fname) if winid > 0 call win_gotoid(winid) else - exe 'edit ' a:fname + " If the Netrw plugin is configured in tree style listing mode + " (i.e. g:netrw_liststyle = 3), then a buffer named 'NetrwTreeListing' + " is shown (i.e. active window). This happens only after the original + " buffer, which has the directory as its name, is focused for the first + " time. We work around this by comparing the 'netrw_curdir' variable of + " the 'NetrwTreeListing' buffer against the directory name. + let netrw_buffer = bufnr("NetrwTreeListing") + let netrw_winid = bufwinid(netrw_buffer) + if netrw_winid > 0 && a:fname == getbufvar(netrw_buffer, "netrw_curdir") + call win_gotoid(netrw_winid) + else + exe 'edit ' a:fname + endif endif endfunction