fix(vim): fix vim tab keybinding fallback. (#763)
parent
adb4bcd13f
commit
d47dac9041
|
|
@ -12,11 +12,16 @@ function! tabby#keybindings#Map()
|
||||||
if !empty(mapcheck('<Tab>', 'i'))
|
if !empty(mapcheck('<Tab>', 'i'))
|
||||||
" fallback to the original <Tab> mapping
|
" fallback to the original <Tab> mapping
|
||||||
let tab_maparg = maparg('<Tab>', 'i', 0, 1)
|
let tab_maparg = maparg('<Tab>', 'i', 0, 1)
|
||||||
|
if toupper(tab_maparg.rhs) == '<NOP>'
|
||||||
|
" if the original <Tab> mapping is <nop>, no need to fallback
|
||||||
|
imap <script><silent><nowait><expr> <Tab> tabby#Accept()
|
||||||
|
else
|
||||||
" warp as function if rhs is expr, otherwise encode rhs as json
|
" warp as function if rhs is expr, otherwise encode rhs as json
|
||||||
let fallback_rhs = tab_maparg.expr ? '{ -> ' . tab_maparg.rhs . ' }' : substitute(json_encode(tab_maparg.rhs), '<', '\\<', 'g')
|
let fallback_rhs = tab_maparg.expr ? '{ -> ' . tab_maparg.rhs . ' }' : substitute(json_encode(tab_maparg.rhs), '<', '\\<', 'g')
|
||||||
" inject <SID>
|
" inject <SID>
|
||||||
let fallback_rhs = substitute(fallback_rhs, '<SID>', "\<SNR>" . get(tab_maparg, 'sid') . '_', 'g')
|
let fallback_rhs = substitute(fallback_rhs, '<SID>', "\<SNR>" . get(tab_maparg, 'sid') . '_', 'g')
|
||||||
exec 'imap <script><silent><nowait><expr> <Tab> tabby#Accept(' . fallback_rhs . ')'
|
exec 'imap ' . (get(tab_maparg, 'script') ? '<script>' : '') . '<silent><nowait><expr> <Tab> tabby#Accept(' . fallback_rhs . ')'
|
||||||
|
endif
|
||||||
else
|
else
|
||||||
" fallback to input \t
|
" fallback to input \t
|
||||||
imap <script><silent><nowait><expr> <Tab> tabby#Accept("\t")
|
imap <script><silent><nowait><expr> <Tab> tabby#Accept("\t")
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue