5

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?

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Exactly what I wanted! Thanks @esauvisky!
1

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.