From 341403d115c088121a42ff1fc23521bf3a6a6ee1 Mon Sep 17 00:00:00 2001 From: james Date: Fri, 22 Jul 2016 10:32:42 -0700 Subject: [PATCH] Change the remapping of movement keys when Pencil mode is enabled to check for user remaps and use those as a sane default. Fixes #49 --- autoload/pencil.vim | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) 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