diff --git a/autoload/pencil.vim b/autoload/pencil.vim index f36a49f..d4fee86 100644 --- a/autoload/pencil.vim +++ b/autoload/pencil.vim @@ -388,10 +388,10 @@ fun! pencil#init(...) abort en if b:pencil_wrap_mode - nn j gj - nn k gk - vn j gj - vn k gk + exe 'nn ' . Mapkey("j", "n") . ' gj' + exe 'nn ' . Mapkey("k", "n") . ' gk' + exe 'vn ' . Mapkey("j", "v") . ' gj' + exe 'vn ' . Mapkey("k", "v") . ' gk' no gk no gj @@ -494,4 +494,20 @@ fun! s:doModelines() abort en endf +function! Mapkey (keys, mode) + " 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 :bn + " :call Mapkey(':bn', 'n') + " " returns + 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 +endfunction + " vim:ts=2:sw=2:sts=2