Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Setting the cursor position upon completion


I had finally sat down and configured zsh new completion system to
somewhat my liking, and yes its seems to take a lot of trial and
errors to get the behaviour one wants.

My configuration I think does the 3 things that you mentioned: 

1. If there is single match, it just inserts
2. If there are more then 1 match, it adds the common prefix, then stops.
3. If you press TAB one more time, menu selection is entered, where
you can use arrow keys to select the match, Enter keys exits selection
_and_ executes the command line
4. While at menu selection you can press ^Z or Alt-backspace, which does
undo, and brings you back to step 2, with the common prefix displayed.
5. If you press Tab on a glob pattern, then the selection menu offers
all the files matching pattern as the first choice, followed by each
file matched by pattern individually, ex:
  echo /usr/s*<TAB>

  gives menu selection of items
  /usr/sbin /usr/src /usr/share

6. Unambiguous matches on a glob in the middle get inserted immediately:
   cd /usr/s*/lo*/zsh<TAB> gets expanded

7. Ambiguous matches on a glob in the middle enter menu selection:
  cd /usr/s*/loca<Tab>

  Enters menu selection with: /usr/src/local /usr/share/locale and
  /usr/s*/loca (orig string)
# control the menu completion with zstyle
setopt no_menu_complete nolistbeep
zmodload zsh/complist
# ksh like binding
bindkey -M viins "\e\\" complete-word
# without this everything gets mixed up for _expand
zstyle ':completion:*:*:*:*' group-name ''
zstyle ':completion:*' completer _expand _complete _match _correct _approximate
# below may need adjusting, if you type ae<tab> it gives bad results
# giving you all 2 letter commands
zstyle ':completion:*' max-errors 4 not-numeric
# I never seen this prompt, where should it appear?
# corrections still work, ie cd /u/l/s/zsh<Tab> works
zstyle ':completion:*' prompt 'Made %e corrections'
zstyle ':completion:*:expand:*:*' tag-order 'all-expansions expansions'
zstyle ':completion:*:*:*:*' group-order all-expansions expansions 
# this enables menu completion, but on the 2nd tab only
# select without =1 does not work the same way
zstyle ':completion:*:*:*:*' menu select=1
zstyle ':completion:*:*:*:*' verbose yes
# without below glob in the middle does not work
zstyle ':completion:*:*:*:*' list-suffixes yes

# Alt-backspace to undo
bindkey -M menuselect "\M-^?" undo
bindkey -M menuselect "^Z" undo
# Incremental search forward and backward like in emacs 
# (requires stty -ixon)
bindkey -M menuselect "^S" history-incremental-search-forward
bindkey -M menuselect "^R" history-incremental-search-backward
bindkey -M menuselect "^N" vi-insert
# shift-tab go backward
bindkey -M menuselect "\e[Z" up-line-or-history
# C-Space
bindkey -M menuselect "^@"  accept-and-infer-next-history
# Make enter exit menu selection and do actual command
# instead of just exiting the menu selection
bindkey -M menuselect "^M" .accept-line
# sort files by date and follow symlinks
zstyle ':completion:*:*:*:*' file-sort date follow
compinit -C
# I like my Esc/ search very much, put it back
bindkey -rM viins "\e/" 

Hopefully this helps,

At Fri, 1 Aug 2008 13:09:07
+0000 (GMT), Julien Duval wrote:
> Hi,                                                                                                       
> I've come to you cause I'm having some trouble setting the cursor position upon completion, and I didn't  
> find a satisfying solution on the web.                                                                    
> My TAB key is bound to the expand-or-complete-prefix widget and I've set the MENU_COMPLETE option in order
> to cycle through all the matches right from the first TAB hit.                                            
> The thing is, when cycling through the matches, the cursor is always moved to the end of each match, which
> I don't want.                                                                                             
> Here is the behaviour I'm looking for:                                                                    
> When hitting TAB for the first time and the first match is inserted,                                      
> (1) if there is more than one match and all of them share a common unambiguous prefix, then move the      
> cursor to the position immediately following the prefix (that is the first ambiguous character).          
> (2) if there is more than one match but they do not ALL share a common prefix, then leave the cursor where
> it was before hitting TAB. This is actually implied by (1).                                               
> (3) if there is only one single match, then move the cursor to the end of the match inserted.             
> The default behaviour already satisfies (3). But I can't seem to find a solution for the other two.       
> I've tried the following command to solve (1), but unfortunately it didn't help and I don't understand    
> why.                                                                                                      
> zstyle ':completion:*' ambiguous true                                                                     
> I've unset the ALWAYS_TO_END option (even though it's already the case by default) but it didn't change   
> anything. Set or unset, the cursor is always moved to the end of the match. Does anyone know the point of 
> this option ?                                                                                             
> Hope the description and my English weren't too confusing.                                                
> Any help would be greatly appreciated.                                                                    
> Thanks,                                                                                                   
> Julien                                                                                                    
> ----------------------------------------------------------------------------------------------------------
> Envoyé avec Yahoo! Mail.
> Une boite mail plus intelligente.

Messages sorted by: Reverse Date, Date, Thread, Author