ZSH tab completion - don't fill in first file
Asked Answered
zsh
D

6

10

If I have files "something1" and "something2" in a folder, how do I make ZSH's tab completion fill in only the common characters? For example, I would type:

som<Tab>

and I want it to fill in with "something", not "something1".

Current zstyles:

zstyle ':completion:*' special-dirs true
zstyle ':completion::complete:*' use-cache on
zstyle ':completion::complete:*' cache-path ~/.zsh/cache/$HOST
zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}
zstyle ':completion:*' list-prompt '%SAt %p: Hit TAB for more, or the character to insert%s'
zstyle ':completion:*' menu select=1 _complete _ignored _approximate
zstyle -e ':completion:*:approximate:*' max-errors \
zstyle ':completion:*' select-prompt '%SScrolling active: current selection at %p%s'
zstyle ':completion:*::::' completer _expand _complete _ignored _approximate
zstyle -e ':completion:*:approximate:*' max-errors \
zstyle ':completion:*:expand:*' tag-order all-expansions
zstyle ':completion:*' verbose yes 
zstyle ':completion:*:descriptions' format '%B%d%b'
zstyle ':completion:*:messages' format '%d'
zstyle ':completion:*:warnings' format 'No matches for: %d' 
zstyle ':completion:*:corrections' format '%B%d (errors: %e)%b'
zstyle ':completion:*' group-name ''
zstyle ':completion:*' matcher-list 'm:{a-z}={A-Z}'
zstyle ':completion:*:*:-subscript-:*' tag-order indexes parameters
# zstyle ':completion:*:processes' command 'ps -au$USER'
zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#)*=0=01;31'
#zstyle ':completion:*:processes' command 'ps ax -o pid,s,nice,stime,args | sed "/ps/d"'
zstyle ':completion:*:*:kill:*:processes' command 'ps --forest -A -o pid,user,cmd'
zstyle ':completion:*:processes-names' command 'ps axho command' 
#zstyle ':completion:*:urls' local 'www' '/var/www/htdocs' 'public_html'
zstyle ':completion:*' hosts $(awk '/^[^#]/ {print $2 $3" "$4" "$5}' /etc/hosts | grep -v ip6- && grep "^#%" /etc/hosts | awk -F% '{print $2}') 
zstyle ':completion:*:*:(^rm):*:*files' ignored-patterns '*?.o' '*?.c~' \
zstyle ':completion:*:functions' ignored-patterns '_*'
zstyle ':completion:*:*:*:users' ignored-patterns \
zstyle ':completion:*:scp:*' tag-order \
zstyle ':completion:*:scp:*' group-order \
zstyle ':completion:*:ssh:*' tag-order \
zstyle ':completion:*:ssh:*' group-order \
zstyle '*' single-ignored show
Disk answered 4/8, 2010 at 21:23 Comment(2)
What do you get if you enter zstyle or grep zstyle ~/.zshrc at the command prompt. I have zstyle ':completion:*' menu select=0 as one setting and while I don't think it has an effect on what you're asking about, I do get the behavior you're seeking.Shayna
Tried that, didn't seem to work out.Disk
S
4

Adding this to ~/.zshrc works for me:

setopt noautomenu
setopt nomenucomplete

https://serverfault.com/a/447549

Submergible answered 9/3, 2021 at 21:6 Comment(0)
S
2

remove line:

setopt menu_completion

from your .zshrc

and it should work fine with filling unambiguous part first.

Sylviasylviculture answered 20/10, 2021 at 20:1 Comment(0)
C
1

It works like that out of the box if you use Zsh's new completion system. Add this to your ~/.zshrc file (or to try it out, just paste it into the command line):

autoload -Uz compinit && compinit
bindkey '^I' complete-word

After this, if you have two files something1 and something2 in your present working dir, and you type

% file s

and then press Tab, it will complete to

% file something

Press Tab again and it will display

something1  something2

under the command line.

You can then keep pressing Tab to cycle through these two.

Corporator answered 29/6, 2020 at 20:16 Comment(0)
S
0

In your zshrc file (at ~/.zshrc) paste this line zstyle ':autocomplete:*' insert-unambiguous yes if previously it was set to no it changing to the above line will work.

Stele answered 31/12, 2021 at 3:29 Comment(0)
P
-1

Check out man zshoptions. It's pretty well organized so that all of the completion options are in a "Completion" section. I think that the option you're looking for is list_ambiguous. if so, you just need to add in the line

setopt list_ambiguous

to your .zshrc

Pazpaza answered 26/3, 2011 at 23:8 Comment(0)
M
-1

Good news: this is totally doable, and you won't need to worry about zstyles. (I believe.) Bad news: it's a bit tricky to answer.

A great explanation of specific zsh completion options related to the problem you're trying to solve can be found in this specific section of the User's Guide to zsh.

Also, you can do a 'man zshoptions' and look for completion-specific options. The answer above mentioning list_ambiguous is part of the answer, but I don't believe it addresses the whole picture. A key question you'll need to ask yourself is "What do I want to happen after I hit TAB the first time and zsh inserts only the common characters?" You can have zsh do a lot of different things on the second TAB press or even the third. Using various combinations of the ZSH completion options can yield a wide variety of useful results. It all depends on what you want.

Good luck!

Magallanes answered 15/12, 2011 at 18:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.