我可以想到几种方法来做到这一点:
使用 vimgrep
使用vimgrep:运行gvim后,输入:
:vimgrep /background/ **/*.vim
这将使用所有匹配项填充快速修复列表(每个文件可能不止一个),因此您可以使用类似:copen
, :cw
, :cn
等进行导航(请参阅:help quickfix
)
使用 vim 的内置聪明才智
Use findstr
给你一个文件列表,然后让 vim 打开这些文件:
findstr /m background *.vim > list_of_files.txt
gvim list_of_files.txt
" In Gvim, read each file into the buffer list:
:g/^/exe 'badd' getline('.')
" Open the files in tabs:
:bufdo tabedit %
这将加载每个文件,但也会保持文件列表打开(您始终可以加载它或其他)。
Edit:
Using :tabedit
在文件列表上不起作用(我只测试过:badd
)。你可以通过使用 badd 然后 bufdo (如上所述)或通过执行类似的操作(将其放入你的 vimrc 中)来解决这个问题:
command! -range=% OpenListedFiles <line1>,<line2>call OpenListedFiles()
function! OpenListedFiles() range
let FileList = getline(a:firstline, a:lastline)
for filename in FileList
if filereadable(filename)
exe 'tabedit' filename
endif
endfor
endfunction
然后只需打开包含所有所需文件名的文件并输入:
:OpenListedFiles
使用 Vim 的服务器功能和一些糟糕的批处理脚本
使用服务器功能和一些批处理脚本魔法(当我使用 bash 时我不明白)
@echo off
REM Welcome to the hideous world of Windows batch scripts
findstr /m background *.vim > list_of_files.txt
REM Run GVIM (may not be required)
gvim
REM Still in command prompt or .bat file here
REM for each line in the file "list_of_files.txt", pass the line to OpenInTab
for /f %%i in (list_of_files.txt) do call:OpenInTab %%i
goto:eof
:OpenInTab
REM Open the file in a separate tab of an existing vim instance
gvim --remote-tab %~1
goto:eof
呃呃呃。
如果是我,我会选择“使用 vim 的内置智能”选项。实际上,这不是真的:我会使用 cygwin 的 bash 脚本,并且只使用 bash,但如果我必须使用本机工具来完成此操作,我会使用内置的聪明方法。