Question

In my bash shell, when my cursor is between text, and I hit Tab, it autocompletes the filename, and when I hit Enter, it inserts the completion at the cursor, and everything after the cursor remains, e.g.

  $ cp foo.ba¦r.baz.py 
             ^  <== cursor position

Hit the Tab key, and now I see:

  $ cp foo.bar.baz.py¦r.baz.py
                     ^ <== cursor position

I like this behavior, particularly when doing a mv or cp and want to modify the original filename. How can I get zsh to do the same thing?

Was it helpful?

Solution

Use expand-or-complete-prefix, adding this to your .zshrc file:

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

Read this page for more details about zsh completion.

OTHER TIPS

Alternatively, you can add the _prefix control function at the end of your zstyle ':completion:*' completer command in your zshrc, so it will look something like this:

zstyle ':completion:*' completer _force_rehash _complete _list _match _prefix

You also need to enable completeinword for this to work:

setopt completeinword

This way you aren't forced to use expansion like you would be by binding expand-or-complete-prefix.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top