Open greenfoo opened 2 years ago
Can you try using &diff to detect if you are in a diff mode and map something differently?
Good idea. I tried it but there are two small problem with this approach:
But your idea gave me another one: it would be nice to have another buffer specific variable which is only set in those buffers opened by dirdiff. Something like this:
--- dirdiff.vim.ori 2022-05-07 22:10:41.828692192 +0200
+++ dirdiff.vim 2022-05-07 22:47:02.066283682 +0200
@@ -234,6 +234,7 @@
return
endif
silent exe "edit ".s:FilenameDiffWindow
+ let b:dirdiff = 1
echo "Defining [A] and [B] ... "
" We then do a substitution on the directory path
" We need to do substitution of the the LONGER string first, otherwise
@@ -530,17 +531,20 @@
if s:LastMode == 2
call <SID>Drop(previousFileA)
silent exec "edit ".s:FilenameA
+ let b:dirdiff = 1
diffthis
silent exec "bd ".bufnr(previousFileA)
call <SID>Drop(previousFileB)
silent exec "edit ".s:FilenameB
+ let b:dirdiff = 1
diffthis
silent exec "bd ".bufnr(previousFileB)
else
let previousFile = (s:LastMode == "A") ? previousFileA : previousFileB
call <SID>Drop(previousFile)
silent exec "edit ".s:FilenameB
+ let b:dirdiff = 1
silent exec "bd ".bufnr(previousFile)
diffthis
@@ -550,9 +554,11 @@
else
"Open the diff windows
silent exec "split ".s:FilenameB
+ let b:dirdiff = 1
" To ensure that A is on the left and B on the right, splitright must be off
silent exec "leftabove vert diffsplit ".s:FilenameA
+ let b:dirdiff = 1
endif
" Go back to the diff window
Then I can do something like this on my .vimrc:
nnoremap <expr> <A-k> b:dirdiff ? ':silent! DirDiffPrev<CR>' : ':cp!<CR>'
nnoremap <expr> <A-j> b:dirdiff ? ':silent! DirDiffNext<CR>' : ':cn!<CR>'
...and it works :)
Let me know if you like this approach and I will happily create a PR.
I map
<A-j>
and<A-k>
to:cprevious
and:cnext
to navigate the "quickfix" list when opened.I would also like to use these same keys to go to the previous and next file while in dirdiff mode (by setting variables
g:DirDiffNextKeyMap
andg:DirDiffPrevKeyMap
). Unfortunately this does not work because the original ("quickfix") mappings are lost when I do this.I see two workarounds for this:
<A-j>
and<A-k>
to execute either:cprevious
/:cnext
or:DirDiffPrev
/:DirDiffNext
.Any thoughts on this?
Thanks!