aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--vim/after/ftplugin/diff.vim18
-rw-r--r--vim/autoload/diff.vim29
2 files changed, 44 insertions, 3 deletions
diff --git a/vim/after/ftplugin/diff.vim b/vim/after/ftplugin/diff.vim
index 798c7089..a52b3fdd 100644
--- a/vim/after/ftplugin/diff.vim
+++ b/vim/after/ftplugin/diff.vim
@@ -8,13 +8,25 @@ if exists('g:no_plugin_maps') || exists('g:no_diff_maps')
finish
endif
-" Modify curly braces to navigate by diff block
+" Maps using autoloaded function for quoted block movement
nnoremap <buffer> <silent> <LocalLeader>[
- \ :call search('\m^@@', 'bW')<CR>
+ \ :<C-U>call diff#MoveBlock(v:count1, 1, 0)<CR>
nnoremap <buffer> <silent> <LocalLeader>]
- \ :call search('\m^@@', 'W')<CR>
+ \ :<C-U>call diff#MoveBlock(v:count1, 0, 0)<CR>
+onoremap <buffer> <silent> <LocalLeader>[
+ \ :<C-U>call diff#MoveBlock(v:count1, 1, 0)<CR>
+onoremap <buffer> <silent> <LocalLeader>]
+ \ :<C-U>call diff#MoveBlock(v:count1, 0, 0)<CR>
+xnoremap <buffer> <silent> <LocalLeader>[
+ \ :<C-U>call diff#MoveBlock(v:count1, 1, 1)<CR>
+xnoremap <buffer> <silent> <LocalLeader>]
+ \ :<C-U>call diff#MoveBlock(v:count1, 0, 1)<CR>
let b:undo_ftplugin .= '|nunmap <buffer> <LocalLeader>['
\ . '|nunmap <buffer> <LocalLeader>]'
+ \ . '|ounmap <buffer> <LocalLeader>['
+ \ . '|ounmap <buffer> <LocalLeader>]'
+ \ . '|xunmap <buffer> <LocalLeader>['
+ \ . '|xunmap <buffer> <LocalLeader>]'
" Set mappings
nmap <buffer> <LocalLeader>p
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