Advertisement
Guest User

Vim locate tools

a guest
Dec 28th, 2018
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VIM 1.76 KB | None | 0 0
  1. fu! ZOPinit()
  2.     if exists("$ZOPDIRS")
  3.         let files = globpath($ZOPDIRS, "**/*")
  4.         let s:fileList = split(files)
  5.     endif
  6. endfu
  7.  
  8. "call ZOPinit()
  9.  
  10. fu! LOCATEIT()
  11.     "treat as a pass through to locate
  12.     let l:index = 1
  13.     let l:numberedMatches = []
  14.     let l:locateinput = input("")
  15.     let l:expressions = split(system('locate '.l:locateinput), '\n')
  16.     for l:expression in l:expressions
  17.         call add(l:numberedMatches, l:index . ". ". l:expression)
  18.         let l:index = l:index + 1
  19.     endfor
  20.     if len(l:numberedMatches) > 0
  21.         let l:index = inputlist(l:numberedMatches)
  22.         if l:index > 0 && l:index <= len(l:numberedMatches)
  23.             let l:index = l:index - 1
  24.             execute "tabnew " . substitute(l:numberedMatches[l:index], "\\(\\d\\+\. \\)","", "")
  25.         endif
  26.     endif
  27. endfu
  28.  
  29.  
  30. fu! ZOP()
  31.     let index = 1
  32.     let matches = []
  33.     let numberedMatches = []
  34.     let expressions = split(input(""))
  35.     if len(expressions) > 0
  36.         for filePath in s:fileList
  37.             let doContinue = 0
  38.             for expression in expressions
  39.                 if filePath !~? expression
  40.                     let doContinue = 1
  41.                     break
  42.                 endif
  43.             endfor
  44.             if doContinue == 0
  45.                 call add(matches, filePath)
  46.                 call add(numberedMatches, index . ". ". filePath)
  47.                 let index = index + 1
  48.             endif
  49.         endfor
  50.         if len(matches) > 0
  51.             let index = inputlist(numberedMatches)
  52.             if index > 0 && index <= len(matches)
  53.                 let index = index - 1
  54.                 execute "e " . matches[index]
  55.             endif
  56.         endif
  57.     endif
  58. endfu
  59. map <leader>op :call LOCATEIT()<enter>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement