From b9c7f446167e6a1f655881df84849958e86145b4 Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Sat, 16 Nov 2019 12:08:00 +0300 Subject: [PATCH 1/3] Fix Mapkey to return queried key instead of 0 if no match --- autoload/pencil.vim | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/autoload/pencil.vim b/autoload/pencil.vim index 63dd0d8..4d61bcb 100644 --- a/autoload/pencil.vim +++ b/autoload/pencil.vim @@ -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 :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 + 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 From 788a6870c7f90b8426f4a1acd0a886b11383eb2d Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Sat, 16 Nov 2019 12:17:39 +0300 Subject: [PATCH 2/3] Bind to whatever users may have remapped 0/$ to instead of directly to 0/$ --- autoload/pencil.vim | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/autoload/pencil.vim b/autoload/pencil.vim index 4d61bcb..d027c1e 100644 --- a/autoload/pencil.vim +++ b/autoload/pencil.vim @@ -386,10 +386,10 @@ fun! pencil#init(...) abort en if b:pencil_wrap_mode ==# s:WRAP_MODE_SOFT - nn $ g$ - nn 0 g0 - vn $ g$ - vn 0 g0 + exe 'nn ' . Mapkey('$', 'n') . ' g$' + exe 'nn ' . Mapkey('0', 'n') . ' g0' + exe 'vn ' . Mapkey('$', 'v') . ' g$' + exe 'vn ' . Mapkey('0', 'v') . ' g0' no g no g From 7d1e536d1d757af75fb6c7c1789d8b3c6d396103 Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Sat, 16 Nov 2019 12:21:17 +0300 Subject: [PATCH 3/3] Map g0/g$ to what used to be 0/$ (similar to j->gj/gj->j) --- autoload/pencil.vim | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/autoload/pencil.vim b/autoload/pencil.vim index d027c1e..19d0e53 100644 --- a/autoload/pencil.vim +++ b/autoload/pencil.vim @@ -392,6 +392,10 @@ fun! pencil#init(...) abort exe 'vn ' . Mapkey('0', 'v') . ' g0' no g no g + nn g0 0 + nn g$ $ + vn g0 0 + vn g$ $ " preserve behavior of home/end keys in popups call s:imap(1, '', 'g')