Skip to content

Instantly share code, notes, and snippets.

@kien
Created November 13, 2011 16:51
Show Gist options
  • Save kien/1362317 to your computer and use it in GitHub Desktop.
Save kien/1362317 to your computer and use it in GitHub Desktop.
" List user-defined commands that don't have a mapping assigned to them.
" Run ":so %".
func! s:UnmappedCommands()
let lst = s:Lst()
for each in range(1, len(lst) - 1)
let str2 = matchstr(lst[each], '[^ ]\+', 4).' '
" Echo each line
echon each.':'
echoh Function
echon str2
echoh None
endfor
cal s:Prompt(lst)
endfunc
func! s:UnmappedCmdsEachCmdPerLine()
let lst = s:Lst()
" Padding whitespaces for the first line
let len = strlen(string(len(lst) - 1))
let wsps = ' '
for each in range(1, len)
let wsps = ' '.wsps
endfor
" Echo the first line
echoh Title
echon wsps.lst[0]
echoh None
for each in range(1, len(lst) - 1)
" Padding whitespaces for each line
let wsp = len - strlen(each)
let nr = each
if wsp
for awsp in range(1, wsp)
let nr = ' '.nr
endfor
endif
let str1 = ' '.nr.' '.strpart(lst[each], 0, 4)
let str2 = matchstr(lst[each], '[^ ]\+', 4)
let str3 = matchstr(lst[each], '[^ ]\+\zs .*$', 4)
" Echo each line
ec str1
echoh Function
echon str2
echoh None
echon str3
endfor
cal s:Prompt(lst)
endfunc
func! s:Lst()
redi => allcoms
sil! com
redi END
let lst = split(allcoms, '\n')
let ic = len(lst) - 1
while ic >= 1
let comm = matchstr(lst[ic], '[^ ]\+', 4)
if hasmapto(comm, 'nvoilc')
cal remove(lst, ic)
endif
let ic -= 1
endwhile
retu lst
endfunc
func! s:Prompt(lst)
echoh Identifier
cal inputsave()
let id = input("Enter a command's ID: ")
cal inputrestore()
echoh None
if !empty(id)
cal feedkeys(':'.matchstr(a:lst[id], '[^ ]\+', 4), 'n')
endif
endfunc
" 2 formats:
cal s:UnmappedCommands()
"cal s:UnmappedCmdsEachCmdPerLine()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment