On 13 July 2016, Yang Luo wrote:
>
> I write a function like this:
> function InsertNumber(start, end, step)
>
> let i = a:start
>
> let curr_line = 0
>
> while i <= a:end
> if a:step <= 0
> echo "Error: step cannot <=0."
> break
> endif
>
> call append(curr_line, i)
>
> let i += a:step
>
> let curr_line += 1
>
> endwhile
> endfunction
>
>
> when I call this function, I type this:
> :echo InsertNumber(8,10,1)
> 8
> 9
> 10
>
>
> 1) How can I give arguement "step" a default value(eg: 1) when define the
> function?
> like a C function:
> void C_func(int a, int b_have_default_val = 1)
> {
>
> ;
> }
Use optional arguments:
function! InsertNumber(start, end, ...)
let step = a:0 > 0 ? a:1 : 1
...
endfunction
> 2)
> I want to print number like this, how to do it?
> 08
> 09
> 10
call append(curr_line, printf("%02d", i))
/lcd
--
--
You received this message from the "vim_dev" 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
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to vim_dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.