filename completion of :find and 'path'

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

filename completion of :find and 'path'

Mikołaj Machowski
Hello,

Is it possible to have filename completion with :find and 'path'
(especially recursive)?

'path' and :find are working nicely, for example
set path+=~/public_html/**
:fin 1A.html

is working nicely editing work/persons/1A.html

But without completion it is only half-useful. There is workaround with
creation of args/buffers list but maintaining of this list can be
troublesome.

Any ideas, wrap scripts, etc?

TIA

m.

--
LaTeX + Vim = http://vim-latex.sourceforge.net/
Vim-list(s) Users Map: (last change 15 May)
 http://skawina.eu.org/mikolaj/vimlist
CLEWN - http://clewn.sf.net

Reply | Threaded
Open this post in threaded view
|

Re: filename completion of :find and 'path'

Yegappan Lakshmanan
Hi,

On 7/1/05, Mikolaj Machowski <[hidden email]> wrote:

> Hello,
>
> Is it possible to have filename completion with :find and 'path'
> (especially recursive)?
>
> 'path' and :find are working nicely, for example
> set path+=~/public_html/**
> :fin 1A.html
>
> is working nicely editing work/persons/1A.html
>
> But without completion it is only half-useful. There is workaround with
> creation of args/buffers list but maintaining of this list can be
> troublesome.
>
> Any ideas, wrap scripts, etc?
>

You can try using the following function:

---------------------------------------------------------------------------------------------------
function! s:EditFile(fpat)
    if &path == ''
        echomsg "Error: 'path' option is empty"
        return
    endif

    " Get all the filenames matching the supplied pattern
    let file_list = globpath(&path, a:fpat)
    if file_list == ''
        echomsg "Error: " . a:fpat . " not found in 'path'"
        return
    endif

    " Save the filenames to a temporary file
    let tmpfile = tempname()

    let old_verbose = &verbose
    set verbose&vim

    exe "redir! > " . tmpfile
    silent echon file_list
    redir END

    let &verbose = old_verbose

    " Change the quickfix error format to parser only filenames
    let old_efm = &efm
    set efm=%f

    " Specify the temporary file as the quickfix file.
    execute "silent! cfile " . tmpfile

    let &efm = old_efm

    " Remove the temporary file
    call delete(tmpfile)

    " Open the quickfix window
    copen
endfunction

command! -nargs=1 EditFile call s:EditFile(<q-args>)
---------------------------------------------------------------------------------------------------

After sourcing the above function, use the ":EditFile" command to
list all the filenames matching the specified pattern in a quickfix
window. For example, the following command

   :EditFile *myfile*

will list all the filenames containing 'myfile' in a quickfix window.
Note that you have to specify the pattern to match the filenames.

You cannot use the Vim custom completion to implement this.
-----------------------------------------------------------------------------------------------
function! EditFileComplete(ArgLead, CmdLine, CursorPos)
    return globpath(&path, a:ArgLead)
endfunction

command! -nargs=1 -bang -complete=custom,EditFileComplete
                \ Edit edit<bang> <args>
-----------------------------------------------------------------------------------------------

In the current implementation of the Vim custom completion
support, Vim will filter out all the returned filenames that doesn't
begin with the supplied argument.

- Yegappan