Reputation: 1631
I'm trying to unmap <C-w>o
which is a default command that executes :only
(:help :only
), so the first thing I tried is:
nmap <c-w>o <nop>
This kind-of works, except if I press <c-w>
, wait more than timeoutlen
ms and then press o
, :only
gets called.
I don't get why <c-w>
-prefixed and other default commands don't timeout after timeoutlen
ms, this is IMHO unexpected.
Previously I had the ZoomWin plugin that defines its own mapping: <c-w>o
effectively overwriting the :only
command, I couldn't understand why sometimes the :only command
got called instead of ZoomWin plugin, the I realized that it got called when the plugin mapping times out (after timeoutlen
ms) and then I pressed o
, calling the default <c-w>o
command instead.
So, is it possibile to make default commands timeout just like custom mappings?
Upvotes: 5
Views: 1272
Reputation: 53604
You should not think about <C-w>o
being one command, you should think instead about <C-w>
like “start window manipulation submode”: like any other multikey vim normal-mode command <C-w>{smth}
(also g*
, z*
, Z*
) is not just immune to timeout, <C-w>%
(<C-w>{any-key-not-mentioned-in-help}
) will do nothing (likely it will beep, but on my system I can’t see (with 'visualbell') or hear beeps), not switch to corresponding parenthesis (which is the default for %
).
You can still disable the <C-w>o
by remapping <C-w>
in the following fashion:
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()
Upvotes: 2
Reputation: 172520
I also don't understand why built-in commands don't abort after 'timeout'
; I would find this more consistent, but this hasn't bothered me so far.
I think I found a way to achieve what you want, but it's cumbersome. You'd have to neutralize the Ctrl-W itself; Ctrl-\ Ctrl-N is like <Esc>
, but without the beep. When I used <Nop>
, subsequent commands somehow wouldn't work until I issued another command in between.
:nnoremap <C-w> <C-\><C-n>
But as this also disables all built-in commands, you have to map them onto themselves:
:nnoremap <C-w><C-w> <C-w><C-w>
:nnoremap <C-w>s <C-w>s
...
This could be automated via a loop (with the exception of Ctrl-W o, which you want mapped to <Nop>
), but it's still ugly.
Upvotes: 1
Reputation: 9273
The default commands doesn't timeout because they probably aren't handled as a mapping. After the 'timeoutlen'
the keys aren't attached to any mapping, as explained in :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.
So the keys on <C-w>o
are interpreted as single characters and triggers the default command. You may consider setting off 'timeout'
and 'ttimeout'
.
Upvotes: 0
Reputation: 196496
Do you want <C-w>o
to do nothing or do you want to map it to something else?
<C-w>o
doesn't seem to be sensible to <nop>
or :unmap
, so it looks like it's not that easy to make it disappear. I have a hard time coming up with a valid reason for that, though. Getting rid of a command because of repeated fatfingering may be a valid reason ("may") but <C-w>o
is not that easy to hit accidentally, fat fingers or not.
You can, however, easily map it to something else, like:
nnoremap <C-w>o o
Upvotes: 0