Key-specific timeoutlen in vim

前端 未结 2 1553
梦毁少年i
梦毁少年i 2021-01-12 05:38

Is it possible to set different timeoutlen depending on typed key? For example, I have short timeout to go with my remapping to jk or

相关标签:
2条回答
  • 2021-01-12 06:40

    There's nothing built-in. With regards to your mapping, you probably mean :inoremap jj <Esc>, and for that to apply quickly, you just need to ensure that there are no other insert mode mappings that start with jj. To avoid that the first j appears only with a delay, you could use :autocmds to toggle the 'timeoutlen' value:

    :autocmd InsertEnter * set timeoutlen=200
    :autocmd InsertLeave * set timeoutlen=1000
    
    0 讨论(0)
  • 2021-01-12 06:42

    The solution proposed by Ingo Karkat will affect all insert mode mappings, so it may break plugins that define other insert mode mappings that are hard to type in so short a time period.

    In order to escape from insert mode without lagging, I have found a smarter way, which leads to plugin better-escape.vim.

    The default shortcut to escape insert mode is jk, you can change it via the following option:

    let g:better_escape_shortcut = 'jj'
    

    It will calculate the time interval between pressing the first char and the second char in the shortcut (the default is 150 ms). If you press those two chars quickly, you will leave insert mode. Otherwise, the characters will be written literally. To adjust the time interval, use the following option:

    let g:better_escape_interval = 200
    
    0 讨论(0)
提交回复
热议问题