My idea is that whenever
&diff is true for a buffer, I would like some mappings to be active when that buffer is the current buffer.
The following attempt works for when I open a session in diff mode via
vimdiff, and almost works when I do
diffthis from a non-
diff session; I say almost because running
:diffthis does not set the mappings because the
BufEnter event is not triggered, so I have to jump away from that buffer and back to it to see the mappings activated.
How can I have the
autocmd be executed even when
:diffthis is executed and, in general, everytime
&diff is/becomes true in the window where the cursor is?
function! Toggle_diffopts(which) exe 'set diffopt' \ . ['+','-'][!!(index(split(&diffopt,','), a:which) + 1)] \ . '=' \ . a:which endfunction function! SetDiffMappings() if &diff nnoremap <buffer> <silent> <Leader>diw :call Toggle_diffopts('iwhite')<CR> nnoremap <buffer> <silent> <Leader>dic :call Toggle_diffopts('icase')<CR> let b:diff_mappings = v:true else if exists('b:diff_mappings') && b:diff_mappings nunmap <buffer> <Leader>diw nunmap <buffer> <Leader>dic let b:diff_mappings = v:false endif endif endfunction augroup DiffMappings autocmd! autocmd BufEnter * :call SetDiffMappings() augroup end
This does not answer my question.