aboutsummaryrefslogtreecommitdiff
path: root/vim/autoload/diff.vim
blob: 29389b95cf82dc219d9519a01ee9d2e6b6b90580 (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 blocks = 0

  " Iterate through buffer lines
  let num = line('.')
  while a:up ? num > 1 : num < line('$')
    let num += a:up ? -1 : 1
    if getline(num) =~# '^@@'
      let blocks += 1
      if blocks == a:count
        break
      endif
    endif
  endwhile

  " Move to line if nonzero and not equal to the current line
  if num != line('.')
    execute 'normal '.num.'G'
  endif

endfunction