Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

zsh: how to make tab completion need no space to next word after cursor?

There is an annoying difference between zsh and bash tab completion:

Imagine you write some command and want to add something at the beginning of the line:

$ compute --some --stuff

then you jump to the beginning of the line and line and start to write sudo (bad example - just to demonstrate)

$ sudcompute --some --stuff
    ^ <---cursor

bash would let you complete sud to sudo while zsh would try to complete sudcompute.

So in this case you would have to write a space, jump back one character and try to tab-complete.

In case you're still used to bash you would try to tab-complete after sud and render the command you started to write into something utterly useless.

So for short: is there an option to let zsh complete the phrase to the left of the cursor regardless whether or not it's terminated by a space?

like image 323
frans Avatar asked Jun 12 '16 09:06

frans


People also ask

How does autocomplete work in zsh?

The completion system go through a series of completers first. They'll try to find matches depending on the context (the command you've typed) using different completion functions. The Zsh module “zstyle” allows you to configure settings for a specific Zsh module or widget.

Can zsh use bash completion?

Zsh can handle bash completions functions. The latest development version of zsh has a function bashcompinit, that when run will allow zsh to read bash completion specifications and functions.


1 Answers

Just looked around in my .zshrc file and I think this is what you want:

bindkey '^i' expand-or-complete-prefix

Where ^i is <Ctrl-I> which is usually tab.

like image 58
Andreas Louv Avatar answered Sep 22 '22 08:09

Andreas Louv