function! AppleT(name) python << EOF import sys import os import re import vim def walkIt(search): fullpath = os.path.expanduser(set_path) fullsearch = ".*%s.*" % ".*".join(search) fullsearch = re.sub(" ","[/.]", fullsearch) bsearch = re.sub(" ",".*[/.].*", search) exactsearch = "%s" % bsearch exclude = re.compile("\.quer$|\.resp$|\.pyc$") ignoredirs = [".svn", "_site-packages"] fullmatch = re.compile(fullsearch, re.I) exactmatch = re.compile(exactsearch, re.I) length = len(fullpath) results = [] exactresults = [] for root, dirs, files in os.walk(set_path): for x in ignoredirs: if x in dirs: dirs.remove(x) for f in files: filename = os.path.join(root,f) if exclude.search(filename): pass elif exactmatch.search(filename): exactresults.append("%s" % filename) elif fullmatch.search(filename): results.append("%s" % filename) if len(results) == 0: return def cmplen(x,y): return cmp(len(x), len(y)) results.sort(cmplen) exactresults.sort(cmplen) results = exactresults + results for i, a in enumerate(results): print "%d: %s" % (i + 1, a[length:]) which = vim.eval('input("Which? ")') if re.match("^[0-9]+$", which) == None: return which = int(which) - 1 vim.command("tabnew " + results[which]) thingtosearch = vim.eval("expand(a:name)") walkIt(thingtosearch) EOF endfunction function! AppleTSetPath(path) python << EOF import vim set_path = vim.eval("expand(a:path)") EOF endfunction if !exists(":AppleTSetPath") command! -nargs=+ AppleTSetPath :call AppleTSetPath() endif if !exists(":CmdT") command! -nargs=+ CmdT :call AppleT() endif