diff --git a/vimrc b/vimrc index c3f46d1..039a7eb 100644 --- a/vimrc +++ b/vimrc @@ -206,6 +206,7 @@ map ]b :call OpenInWebBrowser() "remove search highlight and refresh nnoremap :nohl:syn sync fromstart +map :call CycleDiffAlgorithm() map :call ToggleHex() " }}} "FileTypes: specific vim behaviour {{{ @@ -717,6 +718,31 @@ function CreateScratch() return "" endfunction +function s:CycleDiffAlgorithm() + " TODO: hardcoded map for available diff algorithms, maybe there is a way + " to retrieve it somehow. + let l:algomap = {} + let l:algomap.myers = 'algorithm:minimal' + let l:algomap.minimal = 'algorithm:patience' + let l:algomap.patience = 'algorithm:histogram' + let l:algomap.histogram = 'algorithm:myers' + let l:nextalgo = 'algorithm:myers' + let l:opts = split(&diffopt, ',') + + " find first algorithm: option, if exists. + for item in l:opts + if item =~ 'algorithm:' + let l:nextalgo = get(l:algomap, split(item, ':')[1], l:nextalgo) + break + endif + endfor + + " filter out all the algorithm:... occurrences + let l:opts = add(filter(l:opts, 'v:val !~ "algorithm:"'), l:nextalgo) + let &diffopt = join(l:opts, ',') + echom 'Set diff algorithm to: ' . split(l:nextalgo, ':')[1] +endfunction + "write files as a root using sudo command W w !sudo tee "%" > /dev/null "}}}