Fix Mapkey to return queried key instead of 0 if no match

This commit is contained in:
Caleb Maclennan
2019-11-16 12:08:00 +03:00
parent c847322db8
commit b9c7f44616

View File

@@ -522,20 +522,17 @@ fun! s:doModelines() abort
en
endf
" Pass in a key sequence and the first letter of a vim mode. Returns key
" mapping mapped to it in that mode, else the original key sequence if none.
function! Mapkey (keys, mode) abort
" Pass in a key sequence and the first letter of a vim mode.
" Returns key mapping mapped to it in that mode, else 0 if none.
" example:
" :nnoremap <Tab> :bn<CR>
" :call Mapkey(':bn<CR>', 'n')
" " returns <Tab>
redir => mappings | silent! map | redir END
for map in split(mappings, '\n')
let seq = matchstr(map, '\s\+\zs\S*')
if maparg(seq, a:mode) == a:keys
return seq
endif
endfor
redir => mappings | silent! map | redir END
for map in split(mappings, '\n')
let seq = matchstr(map, '\s\+\zs\S*')
if maparg(seq, a:mode) == a:keys
return seq
endif
endfor
return a:keys
endfunction
" vim:ts=2:sw=2:sts=2