On Tuesday, December 11, 2012 7:33:48 AM UTC-6, A Loumiotis wrote:
> Hi,
> Starting with a file with two lines:
>
> 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?
>
> I was thinking of something of the following terms but I'm not sure how to
> represent the "i" inside a for loop and whether the setline function is
> called correctly (I'm new with VIM scripting):
>
>
> let line=getline(",")
> for i in range(1,3)
> let repl'i'=substitute(line,'\$x','i',"g")
> endfor
> call setline(.,line,repl1,repl2,repl3)???
>
> Thanks,
> Antonis
First, see John's reply.
But I had a big reply written, and thought I sent it; I have no idea what
happened to it.
Here's the highlights:
I'd probably try using a recorded macro. For the first set of lines, it would
rely on CTRL-A in normal mode. For the second set of lines, nr2char() and
char2nr() functions in an expression register in insert mode.
:help CTRL-A
:help complex-repeat
Macros might get a little too complex, and are best for one-shot tasks that you
won't need to do very often. So I would also look at :help curly-brace-names to
fix the initial idea you had for your function. You will also need to get your
setline command right, it should be:
call setline(".",[line,repl1,repl2,repl3])
--
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