4

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

nmap <c-w>o <nop>

这种工作,除非我按<c-w>,等待超过timeoutlenms 然后按o:only被调用。

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

以前我有定义自己映射的 ZoomWin 插件:<c-w>o有效地覆盖:only命令,我不明白为什么有时会:only command调用而不是 ZoomWin 插件,我意识到它在插件映射超时时被调用(在timeoutlenms 之后)和然后我按下,改为o调用默认命令。<c-w>o

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

4

4 回答 4

2

您不应该考虑<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()
于 2012-08-23T14:58:06.333 回答
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
...

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

于 2012-08-23T14:14:12.207 回答
0

你想<C-w>o什么都不做,还是想把它映射到别的东西上?

<C-w>o似乎对<nop>or不太敏感:unmap,所以看起来要让它消失也不是那么容易。不过,我很难找到一个正当的理由。由于反复的胖手指而摆脱命令可能是一个正当的理由(“可能”),但<C-w>o并不那么容易被意外击中,无论是否胖手指。

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

nnoremap <C-w>o o
于 2012-08-23T12:48:03.627 回答
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'

于 2012-08-23T12:54:08.103 回答