I don't know git so I'm not sure it will work in your case, but maybe you could try the following code:
command! -range=% CountGit let b:winview = winsaveview() | <line1>,<line2>call s:count_git()
function! s:count_git() abort range
let counts = repeat(, 4)
let patterns = ['^ ', '^-', '^+', '^ \|^+']
for i in range(4)
exe a:firstline ',' a:lastline 'g/' . patterns[i] . '/let counts[' i '] += 1'
sil! 0put =['leave alone: ', 'remove: ', 'add: ', 'add + leave alone: ']
sil! 4put =counts
sil! %!column -t -s:
if !bufexists('Counts') | file Counts | endif
setl noma bt=nofile noswf nobl bh=wipe
call winrestview(b:winview) | unlet b:winview
It defines a custom command
:CountGit which calls the
The function initializes the lists
counts should contain the number of occurrences of the lines you're interested in, while
patterns contains the description of the latter.
for loop executes a global command for each pattern which increments a number inside
counts for each occurrence of the pattern.
0put =... paste some description text (
4put =... paste the number of occurrences after the 4th line.
1,4g/^/5m.|-j! join the 2 blocks of text (description + counts).
sil! %!column -t -s: align the counts (remove this line if you don't have the shell
The command accepts a range (which by default is
%) so you could for example select only a part of the buffer and type
:'<,'>CountGit to search for the patterns only inside the visual selection.