Loading ...
Sorry, an error occurred while loading the content.

Re: filename completion of :find and 'path'

Expand Messages
  • Yegappan Lakshmanan
    Hi, ... function! s:EditFile(fpat) if &path == echomsg Error: path option is empty return endif Get all the filenames matching the supplied pattern
    Message 1 of 2 , Jul 1 11:39 AM
    • 0 Attachment
      Hi,

      On 7/1/05, Mikolaj Machowski <mikmach@...> 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
    Your message has been successfully submitted and would be delivered to recipients shortly.