On Tue, 6 Jun 2006, Max Dyckhoff wrote:

I am wondering if there is any way to get the tab completion of a
command to open a new file to complete any file in the path, not just
those in the current working directory. Basically, my path variable is:

path=.,c:\...\source,c:\...\source**

and I would like to be able to enter

:sf behavior_fi<tab><enter>

For it to open the file ...\source\ai\behaviour\behavior_fight.inl,
which it won't currently do. Any bright ideas?
[snip]

This was recently discussed on the list (I don't remember when). You can
place something like this in your vimrc:

  command! -nargs=? -complete=custom,PathFileComplete -bang -bar Sfind sfind<bang> 
<args>
  function! PathFileComplete(ArgLead, CmdLine, CursorPos)
    return substitute(globpath(&path, a:ArgLead."*"), "[^\n]\\+/", "", "g")
  endfunction

Instead of using :sfind, use :Sfind (note the capital S). However, if
you have duplicate filenames in the path, you may want to use this
instead so you can specify a count for which duplicate found file is
opened:

  command! -nargs=? -complete=custom,PathFileComplete -count=1 -bang -bar Find 
<count>find<bang> <args>

So if there are 2 "behavior_fight.inl" files, :2Find behavior_fight.inl
will open the second one.

Kudos to Hari for the completion function!

HTH :)
--
Gerald

Reply via email to