Created
February 17, 2017 16:58
-
-
Save tjdevries/acfa49336bc3edd33fe0d0e1160cb53f to your computer and use it in GitHub Desktop.
Get some information about the mappings you currently have active in Vim
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function! s:get_maps() abort | |
return split(execute('map'), "\n") | |
endfunction | |
function! s:get_dict(mapping) abort | |
let map_split = split(a:mapping, ' ') | |
let l:mode = map_split[0] | |
let l:map = map_split[2] | |
return maparg(l:map, l:mode, v:false, v:true) | |
endfunction | |
function! s:get_len_rhs(map_dict) abort | |
return len(a:map_dict['rhs']) | |
endfunction | |
function! s:sum_maps() abort | |
let l:all_maps = s:get_maps() | |
let l:this_total = 0 | |
for this_map in l:all_maps | |
let l:this_total += s:get_len_rhs(s:get_dict(this_map)) | |
endfor | |
let l:info_dict = { | |
\ 'total number of mappings': len(l:all_maps), | |
\ 'total length of mappings': l:this_total, | |
\ 'average length of mappings': l:this_total / len(l:all_maps), | |
\ } | |
return l:info_dict | |
endfunction | |
echo s:sum_maps() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment