aboutsummaryrefslogtreecommitdiff
path: root/vim/autoload/diff.vim
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2018-08-27 17:18:05 +1200
committerTom Ryder <tom@sanctum.geek.nz>2018-08-27 17:18:05 +1200
commit673c96515da477e2a4f14d9466153ff0874777aa (patch)
treeb468bedc1fb438fd582275800e3482fbd758e08c /vim/autoload/diff.vim
parent7167128b2d2f8aa0436529c474718d71d9e20f2e (diff)
downloaddotfiles-673c96515da477e2a4f14d9466153ff0874777aa.tar.gz
dotfiles-673c96515da477e2a4f14d9466153ff0874777aa.zip
Improve diff block navigation in Vim with function
Diffstat (limited to 'vim/autoload/diff.vim')
-rw-r--r--vim/autoload/diff.vim29
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