Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[runcoms/zpreztorc] Suggest changing the key timeout for vi mode users #1347

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

samcv
Copy link
Contributor

@samcv samcv commented Jun 23, 2017

Set the time for zsh to wait for additional keypresses. In vi mode you
should set this to 1 (0.1s) to remove the delay from entering and
exiting vicmd mode. The default is 0.5s.
Recommended in vi mode, but setting too low in emacs mode will not allow
time to enter additional keypresses.

Set the time for zsh to wait for additional keypresses. In vi mode you
should set this to 1 (0.1s) to remove the delay from entering and
exiting vicmd mode. The default is 0.5s.
Recommended in vi mode, but setting too low in emacs mode will not allow
time to enter additional keypresses.
@belak
Copy link
Collaborator

belak commented Jun 28, 2017

Most of the info I can find about this seems to imply that setting KEYTIMEOUT might mess with other things. https://superuser.com/a/648046

It may be worth looking into some of those workarounds as well.

@samcv
Copy link
Contributor Author

samcv commented Jun 28, 2017 via email

@hlecuanda
Copy link

hlecuanda commented Jan 28, 2018

There is a very good reason for the KEYTIMEOUT to be set at 500ms, for vi mode, namely Multiple stroke keybindings and In-seq / Out-seq keybindings

Consider the following cases:

[ lead ] like bindings to group similar functions on a logical prefix

bindkey -M vicmd ",s" prepend-sudo           # bring me a sandwich https://xkcd.com/149/
bindkey -M vicmd ",c" vi-pound-insert        # distilled commenting awesomeness
bindkey -M vicmd ",p" copy-prev-shell-word   # use shell parsing instead of space matching to find prev word

This sort of bindings are very common, specially if you find that your mnemonic space starts having collisions, so how to reconcile standard [ p ]ut register with [ p ]revious-shell-word? by expanding the mnemonic memory space via prefixes or "sub modes" below 200ms or 300s of a second and you'll begin mis-triggering some bindings, because of timeouts. It's worse if you consider -s or In-sequence/Out-sequence bindings that can have an arbitrary length as long as you can enter the complex binding in the span of time between typing the first character and the moment the first sequence character is read and KEYTIMEOUT

sequence-in bindings

this kind of bindings can be "overloaded" by triggering other bindings, as the out-sequence is interpreted as user keyboard input. If timeout is too short, it can become difficult to properly trigger something like
[ esc ][ - ] [ ! ][ ! ]
as [ ! ] and [ - ] are on opposite ends of the keyboard and both require a [ Shift ] modifier on most laptops. 1/10th of a second is plainly not enough, and it doesn't get better with user's age , i know n.n

bindkey -M vicmd -s  "!!" "\e\e0Csudo !! "           # prepend sudo to the previous history command
bindkey -M vicmd -s ",!!" "\e\egg0isudo \eG$a"       # prepend sudo on a multi-line command by vi'ing your way around
bindkey -M vicmd -s "-!!" "\e\eIsudo !!:0 !!:2 !!:1" # prepend sudo to prev history while swapping arguments

stock gold standard

vim timeout is way more granular controlled via 'timeout' 'ttimeout' 'timeoutlen'' and 'ttimeoutlen parameters, but defaults to stock vi's default, which is immutably set at compile time at 1000ms. this is to allow for slower terminals. 5 years ago even 500ms were a good compromise. but today's workloads are shifting to mobile, the bottleneck is not on the serial cable but on the soft-keyboard's response and tiny keys that make hitting the right key fast enough somewhat difficult.

TL;DR

IMHO, KTIMEOUT should be set between 800 and the default 1000 mostly to accommodate mobile workloads. (prezto makes shell usage on mobile[1] ridiculously easy with keybindings, tmux and mosh automation)

[1] Try termux with the zsh package + your prezto config and mosh mobile-side on android, zsh and tmux server-side. its like they were all built for each other

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants