Vim Tips Wiki
We recommend that you log in before editing. This will allow other users to leave you a message about your edit, and will let you track edits via your Watchlist. Creating an account is quick and free.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.

Latest revision Your text
Line 380: Line 380:
   
 
command! -nargs=* Find :call Find(<f-args></pre>
 
command! -nargs=* Find :call Find(<f-args></pre>
  +
----
 
 
Modified above function to use the -path parameter instead of -iname, this allows things like:
 
Modified above function to use the -path parameter instead of -iname, this allows things like:
<pre>
 
 
:Find 'log*htt*err*' /var
 
:Find 'log*htt*err*' /var
</pre>
 
 
Which would find /var/log/httpd/error_log
 
Which would find /var/log/httpd/error_log
<pre>
 
 
Find 'pub*.tpl'
 
Find 'pub*.tpl'
</pre>
 
 
Which would find all .tpl files in public_html
 
Which would find all .tpl files in public_html
 
function! Find(...)<br>
<pre>
 
 
if a:0==2<br>
function! Find(...)
 
if a:0==2
+
let path=a:1<br>
let path=a:1
+
let query=a:2<br>
let query=a:2
+
else<br>
 
let path="./"<br>
else
 
let path="./"
+
let query=a:1<br>
let query=a:1
+
endif<br>
  +
<br>
endif
 
 
if !exists("g:FindIgnore")<br>
 
  +
let ignore = ""<br>
if !exists("g:FindIgnore")
 
let ignore = ""
+
else<br>
 
let ignore = " | egrep -v '".join(g:FindIgnore, "|")."'"<br>
else
 
 
endif<br>
let ignore = " | egrep -v '".join(g:FindIgnore, "|")."'"
 
  +
<br>
endif
 
  +
let l:list=system("find ".path." -type f -path '".query."'".ignore)<br>
 
let l:list=system("find ".path." -type f -path '".query."'".ignore)
+
let l:num=strlen(substitute(l:list, "[^\n]", "", "g"))<br>
  +
<br>
let l:num=strlen(substitute(l:list, "[^\n]", "", "g"))
 
 
if l:num < 1<br>
 
  +
echo "'".query."' not found"<br>
if l:num < 1
 
echo "'".query."' not found"
+
return<br>
return
+
endif<br>
  +
<br>
endif
 
  +
if l:num == 1<br>
 
 
exe "open " . substitute(l:list, "\n", "", "g")<br>
if l:num == 1
 
 
else<br>
exe "open " . substitute(l:list, "\n", "", "g")
 
  +
let tmpfile = tempname()<br>
else
 
let tmpfile = tempname()
+
exe "redir! > " . tmpfile<br>
exe "redir! > " . tmpfile
+
silent echon l:list<br>
silent echon l:list
+
redir END<br>
redir END
+
let old_efm = &efm<br>
let old_efm = &efm
+
set efm=%f<br>
  +
<br>
set efm=%f
 
  +
if exists(":cgetfile")<br>
 
if exists(":cgetfile")
+
execute "silent! cgetfile " . tmpfile<br>
 
else<br>
execute "silent! cgetfile " . tmpfile
+
execute "silent! cfile " . tmpfile<br>
else
 
 
endif<br>
execute "silent! cfile " . tmpfile
 
  +
<br>
endif
 
  +
let &efm = old_efm<br>
 
  +
<br>
let &efm = old_efm
 
 
" Open the quickfix window below the current window<br>
 
 
botright copen<br>
" Open the quickfix window below the current window
 
  +
<br>
botright copen
 
 
call delete(tmpfile)<br>
 
 
endif<br>
call delete(tmpfile)
 
 
endfunction<br>
endif
 
 
command! -nargs=* Find :call Find(<f-args>)
endfunction
 
command! -nargs=* Find :call Find(<f-args>)
 
</pre>
 
Please note that all contributions to the Vim Tips Wiki are considered to be released under the CC-BY-SA
Cancel Editing help (opens in new window)