134989RE: copy and replace with a slight modification a line several times
- Dec 11, 2012A Loumiotis wrote:
> Starting with a file with two lines:Here is a start which converts the first line of input to the
> var1_$x; var2>$x-1
> var3x; var4x==1
> I would like to end up with the following seven line file:
> var1_1; var2>1-1
> var1_2; var2>2-1
> var1_3; var2>3-1
> var3_a; var4_a==1
> var3_b; var4_b==1
> var3_c; var4_c==1
> var3_d; var4_d==1
> How could I automate this procedure?
first three lines of output:
let line = getline(a:linenr)
let result = 
for i in range(1, 3)
call add(result, substitute(line, '\$x', i, 'g'))
call setline(a:linenr, result)
execute a:linenr . 'put =result[1:]'
With the cursor on the first line of input, following converts
the first line:
Or, if the first line to be converted is line 12, this works:
I suspect a complex :s/// with replacement \=... could do the
job, but the script is more maintainable and useful for related
For the second change required, see:
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
- << Previous post in topic Next post in topic >>