I have a few options I like to apply both when Vim is opened in diff
mode and when it is switched to diff
mode, e.g., when calling diffsplit
.
I have the following lines in my ~/.vimrc
:
command! -nargs=* Wrap set wrap linebreak nolist
function! Set_diff_mode_options()
syntax off
set diffopt=filler,internal,algorithm:histogram,indent-heuristic
autocmd VimEnter * windo Wrap .
autocmd VimEnter * windo set nofoldenable
autocmd VimEnter * wincmd p
endfunction
" When loading vim in diff mode, e.g. vimdiff
if &diff
call Set_diff_mode_options()
endif
" When changing to diff mode while vim is open
autocmd OptionSet diff call Set_diff_mode_options()
When Vim starts in diff
mode, all lines of the function are applied correctly. However, when OptionSet
is activated in an existing Vim windows, the autocmd
s defined in the function seems to be ignored.
How can I ensure the function works properly in both cases?
UPDATE 1:
It looks like replacing VimEnter
with CursorMoved
resolves the issue for diffsplit
, but I suspect it will be inefficient because it performs the same operations many times as I am exploring the diff.