Advertisement
Guest User

Untitled

a guest
Jul 28th, 2016
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1.  
  2. function! PrompedFind()
  3. let l:file = input("File name: ")
  4. :call Find(l:file)
  5. endfunction
  6.  
  7. nnoremap <Leader>t :call PrompedFind()<CR>
  8. " Find file in current directory and edit it.
  9. function! Find(name)
  10. " let l:list=system("find . -name '".a:name."' | perl -ne 'print \"$.\\t$_\"'")
  11. " replace above line with below one for gvim on windows
  12. "let l:list=system("find . -type f -name ".a:name." | perl -ne \"print qq{$.\\t$_}\"")
  13. let l:list=system("find . \\( -path ./target -o -path ./.git \\) -prune -o -type f -iname ".a:name." -print | awk '{print NR \t $1}' ")
  14. let l:num=strlen(substitute(l:list, "[^\n]", "", "g"))
  15. if l:num < 1
  16. echo "'".a:name."' not found"
  17. return
  18. endif
  19. if l:num != 1
  20. echo l:list
  21. let l:input=input("Which ? (CR=nothing)\n")
  22. if strlen(l:input)==0
  23. return
  24. endif
  25. if strlen(substitute(l:input, "[0-9]", "", "g"))>0
  26. echo "Not a number"
  27. return
  28. endif
  29. if l:input<1 || l:input>l:num
  30. echo "Out of range"
  31. return
  32. endif
  33. let l:line=matchstr("\n".l:list, "\n".l:input."\t[^\n]*")
  34. else
  35. let l:line=l:list
  36. endif
  37. let l:line=substitute(l:line, "^[0-9]*[\t ]*", "", "")
  38. echo l:line
  39. execute ":e ".l:line
  40. endfunction
  41.  
  42. command! -nargs=1 Find :call Find("<args>")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement