Preventing redefining existing buffer mapping
I want to prevent *noremap
command from remapping an existing sequence, but only if this sequence is local to buffer:
noremap a b
" Will fail, must succeed
noremap <buffer> <unique> a c
noremap <buffer> a b
" Will fail, OK
noremap <unique> <buffer> 开发者_如何学JAVAa c
noremap a b
noremap <buffer> a c
" Will fail, OK
noremap <unique> <buffer> a d
With newer vim one can use maparg()
with fourth argument:
let oldmap=maparg('a', '', 0, 1)
if empty(oldmap) || !oldmap.buffer
noremap <buffer> a c
endif
or, better (also supports older vim), but requires frawor:
execute frawor#Setup('0.0', {'@/mappings': '0.0'})
let oldmap=s:_r.map.maparg('a', 'n', 0)
if empty(oldmap) || !oldmap.buffer
noremap <buffer> a c
endif
精彩评论