Sorry. Although this is one duplicate question of this, but I don't have reputations now, so I can't comment on the above original question. As one workaround, I posted a new question and this is my first question in this vi community. Hope someone can help me.
My question: If I search multiple times in one file, the counter
won't be reinited as 0
between each search (here counter
is to index the searched items). So it will keep increasing if I do the same search twice which is obviously not what needed.
for example, for string 111
, if I searched first time and replaced, it is replaced as 123
, but if I search 222
in the same file without quiting vim, it will be replaced as 456
, which is not what I want( 123
to index them).
So can vim function reinited the counter referenced in the above link every time it gets called?
Specifically, I added one keymap based on above link
"from above link
function! MakeSearchIndex()
let counter = 0
function! SearchIndex() closure
let counter += 1
return counter
endfunction
return funcref('SearchIndex')
endfunction
let SI=MakeSearchIndex()
"my added keymap
cnoremap si s/\v/\=SI()/g<left><left><left><left><left><left><left><left><left>
counter
are you talking about?