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 #699
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

View File

@ -76,24 +76,20 @@ endif
" a:1 optional argument with the following functionality:
" if a:1==1 then the hasmapto(<Plug>) check is skipped.
" this can be used to map different keys to the same <Plug> definition
" if a:1==2 then the mapping is not <buffer> specific
" 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.
" if a:1==2 then the mapping is not <buffer> specific i.e. it is global
function vimwiki#u#map_key(mode, key, plug, ...)
if a:0 && a:1 == 2
let l:bo = ''
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
" global mappings
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
endfunction

View File

@ -487,20 +487,20 @@ if str2nr(vimwiki#vars#get_global('key_mappings').lists)
" change symbol for bulleted lists
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>'
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>'
endif
endfor
" change symbol for numbered lists
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>'
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>'
endif
endfor
@ -510,16 +510,12 @@ if str2nr(vimwiki#vars#get_global('key_mappings').lists)
" Valid only if langmap is a comma separated pairs of chars
let s:l_o = matchstr(&langmap, '\C,\zs.\zeo,')
if s:l_o
if maparg(s:l_o, 'n') ==# ''
exe 'nnoremap <silent><buffer> '.s:l_o.' :call vimwiki#lst#kbd_o()<CR>a'
endif
exe 'nnoremap <silent><buffer> '.s:l_o.' :call vimwiki#lst#kbd_o()<CR>a'
endif
let s:l_O = matchstr(&langmap, '\C,\zs.\zeO,')
if s:l_O
if maparg(s:l_O, 'n') ==# ''
exe 'nnoremap <silent><buffer> '.s:l_O.' :call vimwiki#lst#kbd_O()<CR>a'
endif
exe 'nnoremap <silent><buffer> '.s:l_O.' :call vimwiki#lst#kbd_O()<CR>a'
endif
endif
endif
@ -538,12 +534,8 @@ endfunction
" insert mode table mappings
if str2nr(vimwiki#vars#get_global('key_mappings').table_mappings)
if maparg('<Tab>', 'i') ==# ''
inoremap <expr><buffer> <Tab> vimwiki#tbl#kbd_tab()
endif
if maparg('<S-Tab>', 'i') ==# ''
inoremap <expr><buffer> <S-Tab> vimwiki#tbl#kbd_shift_tab()
endif
inoremap <expr><buffer> <Tab> vimwiki#tbl#kbd_tab()
inoremap <expr><buffer> <S-Tab> vimwiki#tbl#kbd_shift_tab()
endif
" <Plug> table formatting definitions