On Jan 5, 6:59 am, Michal Dorsett <[email protected]> wrote:
> Hi,
>
> Suppose I have the following text in my file:
>
> 9
> 7 4
> 5 8 3
>
> And I need it appearing as an array initialization like so:
> int a[3][3] = {
> {9,1,1},
> {7,4,1},
> {5,8,3}
>
> };
>
> That is, with all the additional array elements filled with 1's.
>
> The construction of the array ('{', '}, ',') using a recording is easy, but
> since the number of 1's that need to be inserted is a function of the row
> number, I am not sure how to automate it using a recording.
>
> I am sure a script can do it, but I am not a vim expert by any means.
>
Try using the expression register with the repeat() and line()
functions. For example, your macro could contain something like:
"=repeat(',1',3-line('.'))^Mp
(where ^M is a literal carriage return, if you are recording a macro
this will get recorded automatically by pressing enter)
--
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