我需要根据一些外部命令的输出构建一个快速修复列表。但是该命令只给了我文件名和行号,例如:
foo.txt:10
bar.txt:20
Run Code Online (Sandbox Code Playgroud)
我想将指定文件的实际内容添加到 quickfix 列表中,例如:
foo.txt:10: this is some line from foofile
bar.txt:20: hello world, we're a line from barfile
Run Code Online (Sandbox Code Playgroud)
这能做到吗?
理想情况下,我希望这是跨平台的,所以可能在纯 VimScript 中,不调用外部命令,如sed或类似的命令?
我当前的行为可以用一个函数来模拟:
function! MyFunc()
let mylist = ["foo.txt:10:...", "bar.txt:20:..."]
cgetexpr mylist
copen
endfunction
call MyFunc()
Run Code Online (Sandbox Code Playgroud)
我希望这些...
部分成为真实文件中的内容......
嗯,基于comp.editors和上的部分相关问题:help readfile
,我想说下面可能有效,但很浪费:
function! MyFunc()
let mylist = ["foo.txt:10:...", "bar.txt:20:..."]
let result = []
for elem in mylist
let temp = split(elem, ":")
let line = elem . ":" . readfile(temp[0], "", temp[1])[temp[1]-1]
call add(result, line)
endfor
cgetexpr line
copen
endfunction
call MyFunc()
Run Code Online (Sandbox Code Playgroud)