13

Is there a way to cancel a completion once it has been started? I sometimes foolishly press tab to autocomplete make targets (only from sheer indolence) and then end up having to wait for a longer time than if I had just typed the whole of "install" or "check" out myself.

I didn't see anything of note in the zshzle man page, but maybe I missed something? Do any other shells have this capability?

EDIT: Trivial answer. So instead: is there a way for zsh to estimate that tab completion would take a relatively long time to execute and instead ask whether the user would like this to be done?

6
  • 2
    ctrl-c doesn't work?
    – llua
    May 26, 2012 at 19:25
  • 1
    Damn it, it does! That didn't occur to me for some reason. I guess I thought Ctrl-C would have done something more dramatic. Delete the question? (Or maybe you want some rep?)
    – Zorawar
    May 26, 2012 at 19:29
  • 1
    I don't think there is a way to estimate the time it takes for a tab completion. You may cache results but that's probably it. May 26, 2012 at 22:31
  • 1
    @zorawar, I am just trying to help, not get high score :]
    – llua
    May 26, 2012 at 23:26
  • 1
    ctrl-c does not work for all zsh's completion mechanisms. If anyone knows of other ways to halt this. It would be great to have that answer here.
    – xer0x
    Sep 30, 2013 at 17:28

2 Answers 2

7

A SIGINT interrupts the current completion operation and brings you back to the line editor. So press Ctrl+C. The effect might not be immediate: the interpreter only checks for signals at certain points during execution (they're frequent, though), and the signal might take a while if the zsh process is blocked in a system call (for example, if it's waiting for a filesystem to respond).

Unfortunately, if you press Ctrl+C at the wrong time and there is no completion in progress by the time the signal is delivered, your current command line will be canceled. This is difficult to fix without having two different interrupt keys, one for completion and one for the rest, and I'm not sure if zsh supports this.

It's not really feasible to warn you if a completion might take a long time. The speed of a completion function is often mainly driven by the speed at which some information can be read from the filesystem; whether this information is in cache or not, how much there is, and what kind of a filesystem it is (e.g. ramdisk, hard disk or NFS mount) has a lot of influence.

1
  • 1
    Perhaps a configurable timeout for tab completion would be a sane default.
    – antiduh
    Jun 14, 2013 at 20:16
3

You could use ctrl+k to cancel the auto-completion. however i can not find any information from zsh guide either, but it does cancel auto-completion.

1
  • for me ctrl+k confirms the current selection
    – xeruf
    Apr 16, 2021 at 16:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.