zsh-users / zsh-autosuggestions

Fish-like autosuggestions for zsh
MIT License
30.33k stars 1.85k forks source link

How can I autocomplete one part of autosuggested path at a time? ("forward dir/") #722

Closed Andrew15-5 closed 1 year ago

Andrew15-5 commented 1 year ago

I know that I can use forward-char with ZSH_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS to be able to autocomplete one character at a time. Also, I know that forward-word can be used to autocomplete one word (anything without spaces) at a time.

I need to autocomplete one directory at a time (forward-dir), that is, until and including next / in "word" in autosuggestion:

*I typed 4 chars and autosuggestion shows up*
vi dir1/dir2/dir3/file
   ^

*hitting forward-word*
vi dir1/dir2/dir3/file
                      ^

*hitting forward-char (partial)*
vi dir1/dir2/dir3/file
    ^

*what I need*
vi dir1/dir2/dir3/file
       ^

*after that I can do something like this (with ZSH_AUTOSUGGEST_STRATEGY=(history completion) set)*
vi dir1/otherdir/file
        ^

vi dir1/otherdir/file
                ^

vi dir1/otherdir/a.txt
                 ^

vi dir1/otherdir/a.txt
                      ^

vi d (init)

forward-word (forward-word)

forward-char (forward-char)

what I need ("forward dir/")

image (start typing different dir)

image ("forward dir/")

image image

I noticed that the desirable behavior is shown by hitting Tab key, but only for the first directory in autosuggestion: if I keep on pressing Tab, it will just start changing autocompleted directory (and show the list of all dirs) in next level and not appending directories from the first autosuggestion. Or I can type 1st char of dir of each level and then press Tab — then it will be like I want but with extra keystrokes. (I don't want to type 1st char of each dir in autosuggested path, only the very 1st char to show the autosuggested path).

ericfreese commented 1 year ago

Does this help? https://unix.stackexchange.com/a/48589

Andrew15-5 commented 1 year ago

Yes, it does! Thank you.