list - How to speed up a search in a long document using python? -
list - How to speed up a search in a long document using python? -
i wondering if possible search in vim using python in order speed search in long document.
i have text document of 140.000 lines. have list (mysearches) 115 different search patterns. want set lines matches in list (hits)
this now:
in range(0,len(mysearches)-1) line in range(1, line("$")) allow idx = match(getline(line), mysearches[i]) if idx >= 0 phone call add(hits, line) endif endfor endfor
"remove double linenumbers:
allow unduplist=filter(copy(hits), 'index(hits, v:val, v:key+1)==-1')
the problem search takes on 5 minutes. how can adapt above search python search?
how this:
let pattern=join(mysearches, '\|') allow mylist = systemlist('grep -n "'.pattern.'" '. shellescape(fnamemodify(@%, ':p')). ' | cutting -d: -f1')
this works joining pattern \|
(e.g. oring different patterns), shelling out , using grep
process pattern. grep should pretty fast, lot more vim , perchance faster either python or perl (of course of study depends on pattern). homecoming value list, containing matching lines. since used -n
switch of grep received matching line numbers in turn cutting out using cut
.
systemlist()
contains output split @ \n
.so mylist should contain lines, matching pattern. of course of study depends on pattern, if utilize standard bre or ere (-e) or perl re (-p switch) should okay. depending on flavor of re desired, joining part needs adjusted.
note untested, real robust solution, 1 add together more error handling (possibly preprocessing of pattern) , split whole part little bit, easier read.
python list search vim match
Comments
Post a Comment