Here is the initial text.
test1
test2
Only two lines in the text.
I want to insert strings sequence into from 5th line into 16th line. I have tried it with below codes.
for i in range(1,12)
echo ".item".i.","
endfor
1.the initial text.
2.to enter into command mode and input the codes
Two problems to be solved.
1.echo command output the first string .item1
before endfor.
for i in range(1,12)
echo ".item".i.","
2.How create the strings sequence into specified line:from 5th till 16th in edited text with vimscript?
The desired result is as below.
Almost done!
What i get is as below with the command :pu! =map(range(1,12), 'printf(''item%1d'', v:val)')
.
Both of them can't work.
:5pu! =map(range(1,12), 'printf(''item%1d'', v:val)')
:5,16pu! =map(range(1,12), 'printf(''item%1d'', v:val)')
The last issue for my desired format is when the cursor is on the 3th line ,how to create the desired output?
In order to insert the missing lines, without inserting unrequired empty lines (-> append()
+ repeat([''], nb)
+ possible negative nb
)
:let lin = 5 - 1
:call append('$', repeat([''], lin-line('$')))
Then, in order to insert what you're looking for (no need for printf()
if you don't want to format the numbers)
:call append(lin, map(range(1,12), '"item".v:val'))
PS: I'd rather avoid :put
when I can as it's kind of difficult to use with complex expressions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With