Cancel zsh tab completion

autocompletezsh

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?

Best Answer

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.