作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在 vimscript 中,如何遍历当前文件中正则表达式的所有匹配项,然后为每个结果运行 shell 命令?
我认为这是一个开始,但我无法弄清楚如何将整个文件提供给它并获得每场比赛。
while search(ENTIRE_FILE, ".*{{\zs.*\ze}}", 'nw') > 0
system(do something with THIS_MATCH)
endwhile
最佳答案
假设我们有一个包含内容的文件:
123 a shouldmatch
456 b shouldmatch
111 c notmatch
123 a shouldmatch
456 b shouldmatch
.*shouldmatch
readfile()
,然后循环遍历各行并使用
matchstr()
检查每一行。 [1]
function! Test001()
let file = readfile(expand("%:p")) " read current file
for line in file
let match = matchstr(line, '.*shouldmatch') " regex match
if(!empty(match))
echo match
" your command with match
endif
endfor
endfunction
~/.vimrc
并使用
call Test001()
调用它。
关于vim - 遍历正则表达式结果 vimscript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13019971/
我是一名优秀的程序员,十分优秀!