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

Re: Menu-completion for particular commands



On May 28,  3:47pm, David Bustos wrote:
} Subject: Menu-completion for particular commands
}
} How do I get zsh to menu-complete arguments to vim and gvim, while leaving
} normal completion for other commands alone?

In 3.0.x, you can't, really; the closest you could come would be to use
`setopt auto_menu' so that one tab does normal completion and two tabs
starts menu completion.  That affects all commands, though.

In 3.1.6+, you can do it with the new completion system.  (You're probably
best off with at least 3.1.7-pre-4, or wait a few days for the real 3.1.7
release.)

If you haven't already set up the completion system, do this:

zsh% autoload -U compinstall
zsh% compinstall

This will lead you through a bunch of menus to configure the completion
system.  (If the above doesn't work, you've probably overwritten zsh's
default value of $fpath; fix that in your ~/.zshrc or wherever and start
again.)  Once you have that ready, you can do this:

zsh% vim <C-x h>
tags in context :completion::complete:vim::
    all-files  (_files _default)

That is, you type v i m space control-X h and the next two lines are what
zsh prints back at you.  These show you the name of the completion context
for that position on that command line, and the set of tags that zsh uses
to look up completion styles in that context.

Next you look through the "Completion System Configuration" section of the
doc to find something about menu completion.  Lo and behold:

menu
     If this is set to true in a given context, using any of the tags
     defined for a given completion, menu completion will be used. The
     tag `default' can be used to match any tag, but a specific tag
     will take precedence.  [... a lot of other stuff ...]

With these two pieces of information, you're ready to write a "zstyle"
command:

zsh% zstyle :completion::complete:vim::default menu true

Presto, menu completion for vim.  You could do a second similar command
for gvim, but instead notice that it's possible to use glob patterns in
any of the places between the colons in a context.  So:

zsh% zstyle ':completion::complete:(g|)vim::default' menu true

The `(g|)' means to match a `g' or nothing.  So there's your style to
menu-complete the arguments of vim and gvim, leaving everything else
alone.  Put it in your .zshrc with all the other styles that compinstall
added for you, and happy tabbing.

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   



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