I need a little help with some vimscript-ing.
I have a huge log file with multiple blocks of text resembling the following:
[log file start]
...
...
Information: Setting NDR rule shield_rule on net a
Information: Setting NDR rule shield_rule on net b
Information: Setting NDR rule shield_rule on net c
Information: Setting NDR rule shield_rule on net d
Information: Setting NDR rule shield_rule on net e
Information: Setting NDR rule shield_rule on net f
Information: Setting NDR rule shield_rule on net g
Information: Setting NDR rule shield_rule on net h
Information: Setting NDR rule shield_rule on net i
Information: Setting NDR rule shield_rule on net j
Information: Setting NDR rule shield_rule on net k
Information: Setting NDR rule shield_rule on net l
Information: Setting NDR rule shield_rule on net m
Information: Setting NDR rule shield_rule on net n
Information: Setting NDR rule shield_rule on net o
Information: Setting NDR rule shield_rule on net p
Information: Setting NDR rule shield_rule on net q
Information: Setting NDR rule shield_rule on net r
...
...
…. <10,000 more lines like above>
….
Information: Updating global clock route.
[log file end]
I would like to write a function bound to ;b
that allows me to skip the entire
block of similar text. For example, place the cursor at the 1st line of text,
hit ;b
and have the cursor move to the 1st line immediately after the block of
similar text.
I realize I can navigate to the end of the file and search backwards for
Information: Setting NDR rule
but there may be multiple block occurrences of
the text and a backwards search would bring me to the end of the last block.
This is what I have so far:
function! SkipBlockDn()
let ref = getline(v:lnum)
execute "normal! j"
let line = getline(v:lnum)
"
"Help needed here to split up the line into words
"Do a word by word comparison between ref and line
"If current line and ref match like 80% or so, consider the match close enough and move to next line
"
while (line ==# ref)
execute "normal! j"
let line = getline(v:lnum)
endwhile
endfunction
nmap <silent> ;b :call SkipBlockDn()<CR>
normal! j
withoutexecute
. You can also usegetline('.')
. Then there is:help split()
or:help =~#
.)