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

Re: TAB at the command line beginning



On Thu, 22 Jul 2004, Igor Ahmetov wrote:

> Is it possible to imitate tcsh's behavior with 'set autolist', which, 
> when TAB pressed just at the beginning of the command line, prints list 
> of files and directories in the current dir (zsh by default just inserts 
> plain TAB, which in my opinion is rather useless).

Zsh offers two options when completing at the beginning of the line:
Insert a tab, or complete.  This normally completes command names, not
local files, because generally the start of line is where you type a
command, but it might complete something else in some contexts.

For example, when I type TAB at the beginning of the command line, I get:

schaefer[501]                                                             
zsh: do you wish to see all 4238 possibilities (3677 lines)?

To get completion at start of line, you have to be using compsys (run 
"compinit" from your startup files), and you must have set the insert-tab 
zstyle properly.  I have it set to "pending" (explained in the docs) so I 
get completion when I'm typing but plain TABs when I'm cut'n'pasting.

If you want to complete something other than command names, you need to 
write a little function and install it as the completion function for the 
-command- context, like so:

  _command_position() {
    if [[ -z "$BUFFER" ]]
    then _files
    else _autocd
    fi
  }
  compdef _command_position -command-

(Note _autocd is the name of the default -command- function.)

On Thu, 22 Jul 2004, Vincent Lefevre wrote:

> It would be much better if this would be configurable. For instance,
> I'd prefer a history-incremental-search-backward.

The way to configure _that_ is to create your own binding for TAB.

  history-search-or-complete-word() {
    if [[ -z "$BUFFER" ]]
    then zle history-incremental-search-backward "$@"
    else zle complete-word "$@"
    fi
  }
  zle -N history-search-or-complete-word
  bindkey '\t' history-search-or-complete-word

You can do more complicated tests than [[ -z "$BUFFER" ]] ... one that
might be interesting is [[ -z "$BUFFER" && -z "$PREBUFFER" ]].



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