Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function! PrompedFind()
- let l:file = input("File name: ")
- :call Find(l:file)
- endfunction
- nnoremap <Leader>t :call PrompedFind()<CR>
- " Find file in current directory and edit it.
- function! Find(name)
- " let l:list=system("find . -name '".a:name."' | perl -ne 'print \"$.\\t$_\"'")
- " replace above line with below one for gvim on windows
- "let l:list=system("find . -type f -name ".a:name." | perl -ne \"print qq{$.\\t$_}\"")
- let l:list=system("find . \\( -path ./target -o -path ./.git \\) -prune -o -type f -iname ".a:name." -print | awk '{print NR \t $1}' ")
- let l:num=strlen(substitute(l:list, "[^\n]", "", "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)\n")
- 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("\n".l:list, "\n".l:input."\t[^\n]*")
- else
- let l:line=l:list
- endif
- let l:line=substitute(l:line, "^[0-9]*[\t ]*", "", "")
- echo l:line
- execute ":e ".l:line
- endfunction
- command! -nargs=1 Find :call Find("<args>")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement