Answers:
以下match设置似乎适用于(A):
:syn match Low /\v(.+)\n(\1\n)/
:syn match Medium /\v(.+)\n(\1\n){2,4}/
:syn match Critical /\v(.+)\n(\1\n){5,}/
:hi Critical ctermfg=red
:hi Medium ctermfg=yellow
:hi Low ctermfg=green
在这里看来顺序很关键。如果Low或Medium匹配之后Critical,则被这些宽松的要求所包含,并且对于Lowwrt也是如此Medium。
加完第3条或第6条重复线后,突出显示的内容不会立即显示,而是在添加完后稍微移动一下。我不确定是什么触发的。
对于B,我想您可以将regex替换为:
/\v(\S+).*\n(\1.*\n)/
一般来说,更换全部(.*)有(\S+).*,并\1用\1.*,或任何构成词你。
首先,这是一个匹配重复行的搜索模式(忽略前导空白的更改):
\zs marks start of the pattern. Everything before here will not be highlighted
^ start of the line
\s* leading whitespace
.\+ match 1 or more non-newline characters
\( \) and use parens to capture this in match group 1
\n match the newline character
\( \)\+ 1 or more
\1 copies of what was in the match group 1
\s* \n with leading whitespace followed by a newline
/^\s*\(.\+\)\n\zs\(\s*\1\n\)\+ the full regex
:help pattern 将提供有关如何制作正则表达式的更多信息
:help syntax 将向您展示如何使用此正则表达式并将其转换为突出显示的内容
学习编写语法脚本可能很困难,因此一个不错的短期解决方案是通过“ 'incsearch'设置”以确保突出显示搜索并映射键以进行上述搜索,从而“即时”执行此操作,即nnoremap <F5> /^\s*\(.\+\)\n\zs\(\s*\1\n\)\+<CR>
yy10p使用完整的正则表达式执行类似的操作,然后选择要删除并点击的部分r<space>。也许我会添加一条命令“用空格替换此行上的选择内容以外的所有内容”,以加快速度。
,r然后<space>在普通/可视模式下将线连接在一起。