在未打开的文件中将行加载到VimScript中的变量中
发布时间:2020-12-15 21:22:42 所属栏目:安全 来源:网络整理
导读:我需要根据一些外部命令的输出构建一个quickfix列表.但该命令只给我文件名和行号,如: foo.txt:10bar.txt:20 我想将指定文件的实际内容添加到quickfix列表中,如: foo.txt:10: this is some line from foofilebar.txt:20: hello world,we're a line from bar
我需要根据一些外部命令的输出构建一个quickfix列表.但该命令只给我文件名和行号,如:
foo.txt:10 bar.txt:20 我想将指定文件的实际内容添加到quickfix列表中,如: foo.txt:10: this is some line from foofile bar.txt:20: hello world,we're a line from barfile 可以这样做吗? 理想情况下,我希望这是跨平台的,所以可能在纯VimScript中,没有调用像sed或类似的外部命令? 模拟 我可以使用以下函数模拟我当前的行为: function! MyFunc() let mylist = ["foo.txt:10:...","bar.txt:20:..."] cgetexpr mylist copen endfunction call MyFunc() 我希望…部分成为真实文件中的内容…… 解决方法
嗯,根据
a partially related question on 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() (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |