diff --git a/autoload/pencil.vim b/autoload/pencil.vim index cb18c27..8dbb605 100644 --- a/autoload/pencil.vim +++ b/autoload/pencil.vim @@ -45,6 +45,14 @@ function! s:detect_wrap_mode() abort return s:WRAP_MODE_DEFAULT endfunction +function! s:imap(preserve_completion, key, icmd) + if a:preserve_completion + execute ":inoremap " . a:key . " pumvisible() ? \"" . a:key . "\" : \"" . a:icmd . "\"" + else + execute ":inoremap " . a:key . " " . a:icmd + endif +endfunction + function! pencil#setAutoFormat(mode) " 1=auto, 0=manual, -1=toggle if !exists('b:last_autoformat') @@ -139,6 +147,11 @@ function! pencil#init(...) abort else set nojoinspaces " only one space after a .!? (default) endif + "if b:wrap_mode == s:WRAP_MODE_SOFT + " " augment with additional chars + " " TODO not working yet with n and m-dash + " set breakat=\ !@*-+;:,./?([{ + "endif endif " because ve=onemore is relatively rare and could break @@ -183,8 +196,10 @@ function! pencil#init(...) abort vnoremap 0 g0 noremap g noremap g - inoremap g - inoremap g + + " preserve behavior of home/end keys in popups + call s:imap(1, '', 'g') + call s:imap(1, '' , 'g' ) else silent! nunmap $ silent! nunmap 0 @@ -201,19 +216,22 @@ function! pencil#init(...) abort nnoremap k gk vnoremap j gj vnoremap k gk - inoremap g - inoremap g noremap gk noremap gj + + " preserve behavior of up/down keys in popups + call s:imap(1, '' , 'g' ) + call s:imap(1, '', 'g') else silent! nunmap j silent! nunmap k silent! vunmap j silent! vunmap k - silent! iunmap - silent! iunmap silent! unmap silent! unmap + + silent! iunmap + silent! iunmap endif " set undo points around common punctuation,