【发布时间】:2015-03-09 21:07:22
【问题描述】:
我正在尝试创建一个函数,它会弹出一个包含单词“模块”的文件列表(不区分大小写)。
当所有 *.f90 都在当前目录中时,我尝试了 :lvim /Module/gj *.f90,但我未能创建像 expand 这样的 globpath() 以便我可以包含和子目录。
所以,我转向了 python。从 python,我得到了完美的列表。我正在插入 python 代码,这可能会显示我的目标:
#!/usr/bin/python
import os
import re
flsts = []
path = "/home/rudra/Devel/dream/"
print("All files==>")
for dirs, subdirs, files in os.walk(path):
for tfile in files:
if tfile.endswith('f90'):
print(os.path.splitext(tfile)[0])
text = open(dirs+'/'+tfile).read()
match = re.search("Module", text)
if match:
flsts.append(os.path.splitext(tfile)[0])
print("The list to be used ==>")
print(flsts)
得到清单后,我想要一个
complete(col('.')), flsts)
问题是,我无法将它包含在 vim 函数中。
能否请我帮忙,以便我可以从 vim 中获取一个列表并在完整的函数中使用它?
我已经检查了this 作为一种可能的解决方案,但不幸的是它不是。 请帮忙。
编辑:更多解释 所以,比如说,在我的工作目录中,我有:
$tree */*.f90
OLD/dirac.f90
OLD/environment.f90
src/constants.f90
src/gencrystal.f90
src/geninp.f90
src/init.f90
其中只有两个有module这个词:
$ grep Module */*.f90
OLD/dirac.f90: 10 :module mdirac
src/constants.f90: 2 :module constants
所以,我希望只弹出inoremap、complete() 和constants 和dirac。
因此,Module 是我在当前工作目录的subdirs 中搜索的keyword,并且只有那些匹配的文件(本例中为 dirac 和常量)应该在complete() 中弹出
【问题讨论】: