aboutsummaryrefslogtreecommitdiff
path: root/vim/autoload/diff.vim
blob: 32e9333a49ebaf49da6ec0eb777da2a25cf5abe0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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