关于默认命令超时的Vim行为

时间:2012-08-23 10:18:23

标签: vim

我试图取消映射<C-w>o这是一个执行:only:help :only)的默认命令,所以我尝试的第一件事就是:

nmap <c-w>o <nop>

除非我按<c-w>,等待时间超过timeoutlen毫秒,然后按o:only才会被调用。

我不明白为什么<c-w> - 前缀和其他默认命令在timeoutlen ms之后不会超时,这是恕我直言。

以前我有ZoomWin插件定义了自己的映射:<c-w>o有效地覆盖了:only命令,我无法理解为什么有时调用:only command而不是ZoomWin插件,我意识到当插件映射超时(timeoutlen ms之后),然后我按下o,调用默认的<c-w>o命令时调用它。

那么,是否可以像自定义映射一样使默认命令超时?

4 个答案:

答案 0 :(得分:1)

我也不明白为什么内置命令在'timeout'之后不会中止;我会发现这更加一致,但到目前为止这并没有让我感到困扰。

我想我找到了达到你想要的方法,但这很麻烦。你必须中和Ctrl-W本身; Ctrl- \ _Ctrl-N与<Esc>类似,但没有哔哔声。当我使用<Nop>时,在我之间发出另一个命令之前,后续命令将无法工作。

:nnoremap <C-w> <C-\><C-n>

但是,由于这也禁用了所有内置命令,您必须将它们映射到自己:

:nnoremap <C-w><C-w> <C-w><C-w>
:nnoremap <C-w>s     <C-w>s
...

这可以通过循环自动完成(除了你想要映射到<Nop>的Ctrl-W o),但它仍然很难看。

答案 1 :(得分:1)

你不应该认为<C-w>o是一个命令,你应该考虑<C-w>像“开始窗口操作子模式”:像任何其他多键vim普通模式命令<C-w>{smth}一样(同样g*z*Z*)不仅免于超时,<C-w>%<C-w>{any-key-not-mentioned-in-help})也不会做任何事情(很可能它会发出哔哔声,但在我身上系统我看不到(用'visualbell')或听到哔哔声),没有切换到相应的括号(这是%的默认值)。

您仍然可以通过以下方式重新映射<C-w>o来停用<C-w>

function s:CtrlW()
    let char=getchar()
    if type(char)==type(0) | let char=nr2char(char) | endif

    if char is# 'o'
        return ''
    endif
    return "\<C-w>".char
endfunction
nnoremap <expr> <C-w> <SID>CtrlW()

答案 2 :(得分:0)

您希望<C-w>o什么都不做,或者您想将其映射到其他内容?

<C-w>o似乎对<nop>:unmap不敏感,所以看起来让它消失并不容易。不过,我很难想出一个有效的理由。由于反复引导而摆脱命令可能是

但是,您可以轻松地将其映射到其他内容,例如:

<C-w>o

答案 3 :(得分:0)

默认命令不会超时,因为它们可能不会作为映射处理。在'timeoutlen'密钥未附加到任何映射后,如:h ttimeout中所述:

'timeout'    'ttimeout'     action  ~
   off      off     do not time out
   on       on or off   time out on :mappings and key codes
   off      on      time out on key codes

If both options are off, Vim will wait until either the complete
mapping or key sequence has been received, or it is clear that there
is no mapping or key sequence for the received characters.  For
example: if you have mapped "vl" and Vim has received 'v', the next
character is needed to see if the 'v' is followed by an 'l'.
When one of the options is on, Vim will wait for about 1 second for
the next character to arrive.  After that the already received
characters are interpreted as single characters.

因此<C-w>o上的键被解释为单个字符并触发默认命令。您可以考虑设置'timeout''ttimeout'