|  | 
 
 楼主|
发表于 2016-7-14 17:58:37
|
显示全部楼层 
| 本帖最后由 luoyanghero 于 2016-7-14 18:01 编辑 
 I complete the function as follow, now I want to add radix option, but I don't know how to get width. Can you help me complement it
 
 function InsertNumber(start, end,...) " step,is_column_first_0_padding,radix(b,d,o,x)
 let l:i = a:start
 let l:curr_line = 0
 if a:0 == 0          " a:0 extra argument numbers
 let l:step = 1
 else
 let l:step = a:1 " the first extra argument
 endif
 if a:0 == 2
 let l:is_padding = 0
 else
 let l:is_padding = 1 "default padding
 endif
 if a:0 == 3
 let l:radix = a:3
 else
 let l:radix = ""
 endif
 if l:radix == "b"
 elseif l:radix == "o"
 elseif l:radix == "x"
 else
 let l:width = float2nr(trunc(log10(a:end))) + 1
 let l:format = '%0'.l:width.'d'
 endif
 while l:i <= a:end
 if l:step <= 0
 echo "Error: step cannot <= 0."
 break
 endif
 if l:is_padding == 1
 call append(curr_line, printf(l:format, l:i))
 else
 call append(curr_line, l:i)
 endif
 let l:i += l:step
 let l:curr_line += 1
 endwhile
 endfunction
 | 
 |