diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2018-08-27 17:18:05 +1200 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2018-08-27 17:18:05 +1200 |
commit | 673c96515da477e2a4f14d9466153ff0874777aa (patch) | |
tree | b468bedc1fb438fd582275800e3482fbd758e08c /vim/autoload | |
parent | Correct a comment (diff) | |
download | dotfiles-673c96515da477e2a4f14d9466153ff0874777aa.tar.gz dotfiles-673c96515da477e2a4f14d9466153ff0874777aa.zip |
Improve diff block navigation in Vim with function
Diffstat (limited to 'vim/autoload')
-rw-r--r-- | vim/autoload/diff.vim | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/vim/autoload/diff.vim b/vim/autoload/diff.vim new file mode 100644 index 00000000..32e9333a --- /dev/null +++ b/vim/autoload/diff.vim @@ -0,0 +1,29 @@ +" Move between diff block headers +function! diff#MoveBlock(count, up, visual) abort + + " Reselect visual selection + if a:visual + normal! gv + endif + + " Flag for the number of blocks passed + let l:blocks = 0 + + " Iterate through buffer lines + let l:num = line('.') + while a:up ? l:num > 1 : l:num < line('$') + let l:num += a:up ? -1 : 1 + if getline(l:num) =~# '^@@' + let l:blocks += 1 + if l:blocks == a:count + break + endif + endif + endwhile + + " Move to line if nonzero and not equal to the current line + if l:num != line('.') + execute 'normal '.l:num.'G' + endif + +endfunction |