bairui

List Generator for Vim

Jan 15th, 2012
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VIM 0.76 KB | None | 0 0
  1. " List Generator
  2. " Barry Arthur, Jan 2012
  3.  
  4. " List(count, start, step)
  5. "   count : number of list items (lines) to generate
  6. "   start : starting number at head of list (default: 1)
  7. "   step  : increment for each successive line (default: 1)
  8. function! List(cnt, ...)
  9.   let val = 1
  10.   let inc = 1
  11.   if a:0 > 0
  12.     let val = a:1
  13.     if a:0 > 1
  14.       let inc = a:2
  15.     endif
  16.   endif
  17.   exe "normal! " . a:cnt . "o"
  18.   exe "'[,']s/^/\\=(((line('.')-line(\"'[\")+1)*inc)-(inc-val))/"
  19. endfunction
  20.  
  21. command! -nargs=+ List call List(<f-args>)
  22.  
  23. finish
  24.  
  25. " examples:
  26. "
  27. " :List 5
  28. "1
  29. "2
  30. "3
  31. "4
  32. "5
  33. "
  34. " :List 5 3
  35. "3
  36. "4
  37. "5
  38. "6
  39. "7
  40. "
  41. " :List 5 3 4
  42. "3
  43. "7
  44. "11
  45. "15
  46. "19
  47. "
  48. " :List 5 4 3
  49. "4
  50. "7
  51. "10
  52. "13
  53. "16
  54. "
  55. " :List 5 101 101
  56. "101
  57. "202
  58. "303
  59. "404
  60. "505
Advertisement
Add Comment
Please, Sign In to add comment