Suppose I have a file with the following text:
aaa
bbb
ccc
bbb
ccc
eee
I need to add a missing line ddd after the second occurrence of ccc.
For that reason, use of the built-in search() function, as suggested here, won't work, because that will find the first occurrence.
I have the beginnings of a vimscript function:
function! addLine()
normal /bbb
normal /bbb
" MISSING LINE
wq!
endfunction
Is it possible to do this just using normal mode etc? If so, how?
search()should find the next occurrences.call search("bbb") | call search("bbb")orfor i in range(10) | call search("bbb") | endfor, etc.search("ccc") | search("bbb")I seem to end up at the firstbbbnot the second?:call search("ccc") | call search("bbb")gets me to line 4 (the secondbbb).search("ccc", "e")instead - it should move the cursor to the end of the match, but it seems that behaviour varies depending on it was called, so specifying that behaviour explicitly using theeflag should fix that.