I'm trying to write a little function that will help when I'm debugging code with Stata. All I want is for vim to count up the number of times a line begins with di "here
and then insert di "here XX"
into the current line in the buffer, where XX
is the number of times.
This is what I have:
fun! ADD_Here()
let n=[0] | bufdo %s/^di\ \"here\zs/\=map(n,'v:val+1')[1:]/ge
put='di \"here ' . n[0] . '\"'
endfun
nmap <leader>d :<C-U>call ADD_Here()<CR>
This works almost exactly as intended, it does all the counting and inserts text, but it always puts the second insert right below the first one, and then the third below the second, etc. How do I modify this so it inserts at the current line?
For citation purposes, I got the code for the let n=[0]...
statement here.