One way which might offer the solution you want, is incremental-complete-word
:
zle -N incremental-complete-word
bindkey '^Xi' incremental-complete-word
This loads the funtion and binds it to Ctrl-X i. Now you can try it:
> k^Xi
incremental (complete): -no prefix-
In this example the letter k
was typed, followed by Control-X i.
> kil
incremental (complete): kill
I typed il
and now there was one possible completion (kill
). One could accept that and press enter.
> kill^D
incremental (complete): -no prefix-
- external command -
kill killall killall5
By typing Ctrl-D the zsh shows possible completions.
From zshcontrib(1)
:
incremental-complete-word
This allows incremental completion of a word. After starting this command, a list of completion choices can be shown after every character you type, which you can delete with ^H or DEL. Pressing return accepts the completion so far and returns you to normal editing (that is, the command line is not immediately executed). You can hit TAB to do normal completion, ^G to abort back to the state when you started, and ^D to list the matches.
Second answer tries to explain that you need to do two things:
1_ make sure your general matching rules are not case-insensitive (matcher-list
) - from the updated question it's not,
2_ change Unix/(Type/)_hosts (the actual location might vary, but not the Unix/_ssh - this one handles ~/.ssh/config
hosts, see below) last 2 lines to:
_wanted hosts expl host \
compadd -M 'm:{a-z}={A-Z} r:|.=* r:|=*' -a "$@" - _hosts
All of this was already summarized in my answer, so simply try doing this without reading all the rationale before. Also, since your global config is not case-insensitive, the @zeppelin's answer should also work, although it doesn't use $fpath and removes also small->CAPS matching of the hosts.
I did test this with your settings from the update and it works as expected.
Update: remember that zsh
keeps it's functions loaded, so after modifying the _hosts
you need to reload it either by logging in fresh, or:
unfunction _hosts
autoload -Uz _hosts
Also remember that zsh
can have the scripts 'compiled' in zwc
form (zcompile [file]
) and if such file exists and is newer than the source it would be used instead.
Ad. update 2:
Handling the ~/.ssh/config
defined hosts is actually pretty much the same as for _hosts
- depending on your zsh version in either Unix/(Command/)_ssh or Unix/(Type/)_ssh_hosts change the
compadd -M 'm:{a-zA-Z}={A-Za-z} r:|.=* r:|=*' "$@" $config_hosts
line to
compadd -M 'm:{a-z}={A-Z} r:|.=* r:|=*' "$@" $config_hosts
Best Answer
From experimentation, it looks like zsh is indeed using
.ssh/known_hosts
for its autocompletion, but it only reads that at startup/first use.Deleting the offending host (
ssh-keygen -R hostname
or simply editing.ssh/known_hosts
), then restarting the shell seems to work.