vim统计代码行数

nmap <silent> wc :call CountAllSourceLines()<cr>
function! CountOneSourceLines()
silent! redir => dummy
silent! %s+<!--/_./{-}-->++g
silent! %s+//*/_./{-}/*/++g
silent! %s+^//.*$++g
silent! g+^$+d
let s:count = line("$")
silent undo
redir END
return s:count
endfunction

function! CountAllSourceLines()
silent! redir => buflist
silent! buffers!
redir END

let s:total = 0
for buf in split(buflist, '/n')
let bits = split(buf, ' ')
silent! exe "b!" . bits[0]
let s:total = s:total + CountOneSourceLines()
endfor

echo "there are " . s:total . " lines source code in total"
endfunctio

你可能感兴趣的:(vim,exe)