abstract
| - to locate the file and then edit it. I was trying to find if there is some solution directly in Vim, and haven't found one. Closest were :find and :globpath(). :find works nearly as I need, but unfortunatelly it opens the first file of a given name without telling me that there are more. For globpath() I was unable to make it work with the '**' construction, so that it would look into all subdirectories under current directory. So I wrote this small function. You can use it like this: :Find whatever.c - this opens the file "src/core/whatever.c" If there is more than one match, it will present you a selection: :Find Makefile 1 ./src/Makefile 2 ./src/core/Makefile 3 ./src/api/Makefile ... 89 ./src/deelply/hidden/Makefile 90 ./Makefile Which ? (CR=nothing) You may also use wildchars (whatever find(1) knows). :Find *stream*.c 1 ./src/core/i_stream.c 2 ./src/core/o_stream.c 3 ./src/core/streamio.c Which ? (CR=nothing) The function itself: " Find file in current directory and edit it. function! Find(name) let l:list=system("find . -name '".a:name."' | perl -ne 'print \"$.\ $_\"'") " replace above line with below one for gvim on windows " let l:list=system("find . -name ".a:name." | perl -ne \"print qq{$.\ $_}\"") let l:num=strlen(substitute(l:list, "[^
]", "", "g")) if l:num < 1 echo "'".a:name."' not found" return endif if l:num != 1 echo l:list let l:input=input("Which ? (CR=nothing)
") if strlen(l:input)==0 return endif if strlen(substitute(l:input, "[0-9]", "", "g"))>0 echo "Not a number" return endif if l:input<1 || l:input>l:num echo "Out of range" return endif let l:line=matchstr("
".l:list, "
".l:input." [^
]*") else let l:line=l:list endif let l:line=substitute(l:line, "^[^ ]* ./", "", "") execute ":e ".l:line endfunction command! -nargs=1 Find :call Find("")
|