For example, if we use the following mapping:
We also experience lagging when we press ; in insert mode. So we can also do the same thing. We check if the time interval between pressing the two chars is below the time threshold. If that is the case, we execute its original intended mapping, otherwise, we just insert the character literally.
Here is a crude implementation:
let g:my_map = {";;": "\<Esc>mmA;\<Esc>`ma"}
let g:char_press_time = {}
inoremap <expr> ; My_map()
augroup log_press_time
autocmd!
autocmd InsertCharPre * call Log_char()
augroup END
function! Log_char() abort
if v:char == ';'
let g:char_press_time[';'] = reltime()
endif
endfunction
function! My_map() abort
let idx = col('.')
let pre_idx = idx-1
let pre_char = getline('.')[pre_idx-1]
if pre_char == ';'
let interval = reltimefloat(reltime(g:char_press_time[";"])) * 1000
echomsg "interval:" interval
if interval < 200
return "\b" . g:my_map[";;"]
else
return ";"
endif
else
return ";"
endif
endfunction
For example, if we use the following mapping:
We also experience lagging when we press
;in insert mode. So we can also do the same thing. We check if the time interval between pressing the two chars is below the time threshold. If that is the case, we execute its original intended mapping, otherwise, we just insert the character literally.Here is a crude implementation: