【问题标题】:Lag in InsertLeave of VimVim 的 InsertLeave 滞后
【发布时间】:2014-09-26 11:45:31
【问题描述】:

我在.vimrc 中有这些行,用于更改 Vim 插入模式的状态行颜色。 StatusLine 快速响应InsertEnter。但是,对于InsertLeave,大约有。 --INSERT-- 消失和 StatusLine 颜色变化之间有 1 秒的延迟。可以请我帮忙吗?

set laststatus=2
if version >= 700
  au InsertEnter * hi StatusLine term=reverse ctermbg=15 ctermfg=22
  au InsertLeave * hi StatusLine term=reverse ctermbg=16 ctermfg=0
endif

我试过:au Insertleave,只显示一个命令:

--- Auto-Commands ---
InsertLeave
    *         hi StatusLine term=reverse ctermbg=16 ctermfg=0

感谢任何帮助。

谢谢

【问题讨论】:

    标签: vim statusline


    【解决方案1】:

    Vim 无法判断您正在离开插入模式,因为它所看到的只是一个转义。箭头键通常设置为终端 vim 解释为 <ESC>OA<ESC>OB<ESC>OC<ESC>OD。所以 vim 在执行任何操作之前都在等待序列中的下一个键。这也是如果您键入 <ESC>O 时,O 只是在屏幕上停留一秒钟而不是在当前行上方打开新行的原因。

    Vim 使用timeoutlen 来确定按键之间的等待时间。默认为 1000 毫秒。如果你愿意,你可以减少它,但它会使键入映射更加困难。

    如果您紧接着键入不属于某些映射的内容,自动命令也将被更快地触发。

    要查看的相关选项是 :h timeout:h ttimeout:h timeoutlen:h ttimeoutlen

    【讨论】:

      【解决方案2】:

      您可以在当前 vim mode check 中使用 timer_start 函数,仅在按下 Escape 键而不是在序列内(箭头移动、键绑定等)时执行您的命令。

      function <SID>condInsertLeave()
          if mode() == "n"
              hi StatusLine term=reverse ctermbg=16 ctermfg=0
          endif
      endfunction
      
      autocmd InsertLeave * call timer_start(200, { tid -> <SID>condInsertLeave()})
      

      【讨论】:

        猜你喜欢
        • 2011-04-02
        • 2012-06-01
        • 2023-03-06
        • 1970-01-01
        • 1970-01-01
        • 2017-07-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多