Allow buffer local mappings to overwrite existing mappings.

If the fileype is vimwiki then the vimwiki mappings take precedence.
Global mappings will not be overwritten. Closes 
This commit is contained in:
Rane Brown 2019-05-24 20:41:12 -06:00
parent d045ad4db0
commit 6ec85cd0e8
2 changed files with 19 additions and 31 deletions
autoload/vimwiki
ftplugin

@ -76,24 +76,20 @@ endif
" a:1 optional argument with the following functionality: " a:1 optional argument with the following functionality:
" if a:1==1 then the hasmapto(<Plug>) check is skipped. " if a:1==1 then the hasmapto(<Plug>) check is skipped.
" this can be used to map different keys to the same <Plug> definition " this can be used to map different keys to the same <Plug> definition
" if a:1==2 then the mapping is not <buffer> specific " if a:1==2 then the mapping is not <buffer> specific i.e. it is global
" This function maps a key sequence to a <Plug> command using the arguments
" described above. If there is already a mapping to the <Plug> command or
" the assigned keys are already mapped then nothing is done.
function vimwiki#u#map_key(mode, key, plug, ...) function vimwiki#u#map_key(mode, key, plug, ...)
if a:0 && a:1 == 2 if a:0 && a:1 == 2
let l:bo = '' " global mappings
else
let l:bo = '<buffer> '
endif
if a:0 && a:1 == 1
if maparg(a:key, a:mode) ==# ''
exe a:mode . 'map ' . l:bo . a:key . ' ' . a:plug
endif
else
if !hasmapto(a:plug) && maparg(a:key, a:mode) ==# '' if !hasmapto(a:plug) && maparg(a:key, a:mode) ==# ''
exe a:mode . 'map ' . l:bo . a:key . ' ' . a:plug exe a:mode . 'map ' . a:key . ' ' . a:plug
endif
elseif a:0 && a:1 == 1
" vimwiki buffer mappings, repeat mapping to the same <Plug> definition
exe a:mode . 'map <buffer> ' . a:key . ' ' . a:plug
else
" vimwiki buffer mappings
if !hasmapto(a:plug)
exe a:mode . 'map <buffer> ' . a:key . ' ' . a:plug
endif endif
endif endif
endfunction endfunction

@ -487,20 +487,20 @@ if str2nr(vimwiki#vars#get_global('key_mappings').lists)
" change symbol for bulleted lists " change symbol for bulleted lists
for s:char in vimwiki#vars#get_syntaxlocal('bullet_types') for s:char in vimwiki#vars#get_syntaxlocal('bullet_types')
if !hasmapto(':VimwikiChangeSymbolTo '.s:char.'<CR>') && maparg('gl'.s:char, 'n') ==# '' if !hasmapto(':VimwikiChangeSymbolTo '.s:char.'<CR>')
exe 'noremap <silent><buffer> gl'.s:char.' :VimwikiChangeSymbolTo '.s:char.'<CR>' exe 'noremap <silent><buffer> gl'.s:char.' :VimwikiChangeSymbolTo '.s:char.'<CR>'
endif endif
if !hasmapto(':VimwikiChangeSymbolInListTo '.s:char.'<CR>') && maparg('gL'.s:char, 'n') ==# '' if !hasmapto(':VimwikiChangeSymbolInListTo '.s:char.'<CR>')
exe 'noremap <silent><buffer> gL'.s:char.' :VimwikiChangeSymbolInListTo '.s:char.'<CR>' exe 'noremap <silent><buffer> gL'.s:char.' :VimwikiChangeSymbolInListTo '.s:char.'<CR>'
endif endif
endfor endfor
" change symbol for numbered lists " change symbol for numbered lists
for s:typ in vimwiki#vars#get_syntaxlocal('number_types') for s:typ in vimwiki#vars#get_syntaxlocal('number_types')
if !hasmapto(':VimwikiChangeSymbolTo '.s:typ.'<CR>') && maparg('gl'.s:typ, 'n') ==# '' if !hasmapto(':VimwikiChangeSymbolTo '.s:typ.'<CR>')
exe 'noremap <silent><buffer> gl'.s:typ[0].' :VimwikiChangeSymbolTo '.s:typ.'<CR>' exe 'noremap <silent><buffer> gl'.s:typ[0].' :VimwikiChangeSymbolTo '.s:typ.'<CR>'
endif endif
if !hasmapto(':VimwikiChangeSymbolInListTo '.s:typ.'<CR>') && maparg('gL'.s:typ, 'n') ==# '' if !hasmapto(':VimwikiChangeSymbolInListTo '.s:typ.'<CR>')
exe 'noremap <silent><buffer> gL'.s:typ[0].' :VimwikiChangeSymbolInListTo '.s:typ.'<CR>' exe 'noremap <silent><buffer> gL'.s:typ[0].' :VimwikiChangeSymbolInListTo '.s:typ.'<CR>'
endif endif
endfor endfor
@ -510,19 +510,15 @@ if str2nr(vimwiki#vars#get_global('key_mappings').lists)
" Valid only if langmap is a comma separated pairs of chars " Valid only if langmap is a comma separated pairs of chars
let s:l_o = matchstr(&langmap, '\C,\zs.\zeo,') let s:l_o = matchstr(&langmap, '\C,\zs.\zeo,')
if s:l_o if s:l_o
if maparg(s:l_o, 'n') ==# ''
exe 'nnoremap <silent><buffer> '.s:l_o.' :call vimwiki#lst#kbd_o()<CR>a' exe 'nnoremap <silent><buffer> '.s:l_o.' :call vimwiki#lst#kbd_o()<CR>a'
endif endif
endif
let s:l_O = matchstr(&langmap, '\C,\zs.\zeO,') let s:l_O = matchstr(&langmap, '\C,\zs.\zeO,')
if s:l_O if s:l_O
if maparg(s:l_O, 'n') ==# ''
exe 'nnoremap <silent><buffer> '.s:l_O.' :call vimwiki#lst#kbd_O()<CR>a' exe 'nnoremap <silent><buffer> '.s:l_O.' :call vimwiki#lst#kbd_O()<CR>a'
endif endif
endif endif
endif endif
endif
function! s:CR(normal, just_mrkr) function! s:CR(normal, just_mrkr)
if vimwiki#vars#get_global('table_mappings') if vimwiki#vars#get_global('table_mappings')
@ -538,13 +534,9 @@ endfunction
" insert mode table mappings " insert mode table mappings
if str2nr(vimwiki#vars#get_global('key_mappings').table_mappings) if str2nr(vimwiki#vars#get_global('key_mappings').table_mappings)
if maparg('<Tab>', 'i') ==# ''
inoremap <expr><buffer> <Tab> vimwiki#tbl#kbd_tab() inoremap <expr><buffer> <Tab> vimwiki#tbl#kbd_tab()
endif
if maparg('<S-Tab>', 'i') ==# ''
inoremap <expr><buffer> <S-Tab> vimwiki#tbl#kbd_shift_tab() inoremap <expr><buffer> <S-Tab> vimwiki#tbl#kbd_shift_tab()
endif endif
endif
" <Plug> table formatting definitions " <Plug> table formatting definitions
nnoremap <silent><buffer> <Plug>VimwikiTableAlignQ nnoremap <silent><buffer> <Plug>VimwikiTableAlignQ