我正在查看可能具有多个连续相同行的文件。
有没有一种简单的方法可以跳到下一个不同的行?
或者,我希望能够折叠所有等于初始行的行,仅显示折叠的行数。
您可以定义自己的折叠表达式:
首先设置 fdm:
:set fdm=expr
然后
:set foldexpr=getline(v:lnum)==#getline(v:lnum-1)?1:0
现在你可以通过输入zM, 来测试关闭所有折叠,如果你幸运的话 ^_^ 所有重复的行都被折叠了。
您可以键入zR以打开所有折叠。
如果它有效并且您经常打开此类文件,则可以将上述行放入您的 .vimrc.(au with ft) 如果只有一次工作,您可以将模式行写入该文件。
试试这个:
:nmap <F2> "1y$<CR>/^\(<C-R>1$\)\@!<CR>
它将 F2 映射到:
This seems to work well, unless the text of your copied line has escaped characters that will confuse the search regexp. This is because register 1 is just dropped into the search expression without escaping. This would be tricky to fix reliably, but for normal log files, it shouldn't be much of a problem.
Also: if you're not married to vim and just need to read the non-consecutively-duplicated lines of a file, the canonical UNIX way is:
uniq filename
If you want to be in vim but won't need to make changes to the file, try:
:%!uniq
(If you try the latter, be sure to exit without saving)