Thursday, April 2, 2015

Keyword completion in Bash and Vim [Was: How to get to the helppage of shiftwidth in options.txt?]

On 01.04.15 17:25, Peng Yu wrote:
> ~$ compgen -c ls
> ls
> ls
> lsof
> lsappinfo
> lsbom
> lsm
> lsvfs
> ls

Or, more succinctly:

$ ls<Tab>
ls lsblk lscpu lsmod lspci lsusb
lsattr lsb_release lsinitramfs lsof lspgpot

Compare, in Vim:

:h complet<Tab> # Type that,
complete() # and with each succeeding <Tab>
'complete' # ONE new alternative is presented.
'completeopt' # Here I have omitted the leading :h
complete_add() # for clarity, BUT
'completefunc' # when the one you want pops up, just
complete-items # press <Enter> to view that help page.
:h complete_CTRL-E<Enter>
...

Now that you understand how it works, I'm sure it's clear that the two
are already highly equivalent, with the added advantage that we do not
need to type anything - just whack tab until we hit enter on the desired
selection.

However, if preferred, then by all means invoke the compgen-like
broadside:

:h complet<Ctrl-D>
complete() sql-completion cmdline-completion
'complete' ins-completion-menu sql-completion-customization
'completeopt' sql-completion-maps :command-completion
complete_add() sql-completion-views new-omni-completion
'completefunc' sql-completion-static omni-sql-completion
complete-items sql-completion-tables popupmenu-completion
complete_CTRL-E sql-completion-columns :command-completion-custom
complete_CTRL-Y sql-completion-dynamic :command-completion-customlist
complete_check() sql-completion-tutorial g:ada_extended_completion
complete-functions sql-completion-filetypes CompleteDone
completion-functions sql-completion-procedures
ins-completion :command-complete

Of course, this is more powerful than the simplistic bash compgen. It
needs to be, because users do not always know whether the precise
completion-guff they're seeking on a particular day starts with, end
with, or has "complet" in the middle. Nor do they know if it is
"complete" or "completion".

If the need for the extra power in Vim is not yet obvious, please
consider a comparable bash case: I have 1160 subject-related mail
folders just at the minute. (93 of them Vim-related) Simple filename
completion is entirely inadequate, since the keyword I'm using might be
anywhere in the filename. So I use a customised mail-ls:

mls ()
{
ls -xF ~/mail/*$1*
}


Now the similarity between Vim and Bash is almost complete.

Erik

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment