Skip to content

Instantly share code, notes, and snippets.

@mhinz
Created September 10, 2013 07:11
Show Gist options
  • Save mhinz/6505968 to your computer and use it in GitHub Desktop.
Save mhinz/6505968 to your computer and use it in GitHub Desktop.
function! s:count_characters(bang) range abort
let nchars = 0
let lines = a:bang ? range(1, line('$')) : range(a:firstline, a:lastline)
for line in lines
let nchars += strlen(getline(line))
endfor
if a:bang
echomsg '>>> The file contains '. nchars .' characters.'
else
echomsg '>>> Lines '. a:firstline .' to '. a:lastline .' contain '. nchars .' characters.'
endif
endfunction
command -range -bang -bar Count <line1>,<line2>call s:count_characters(<bang>0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment