How to generate a number sequence in file using vi or Vim?

前端 未结 10 2064
野趣味
野趣味 2020-12-07 09:47

Is there a way to generate a number sequence in vi or Vim?

For example, for an arbitrary range of lines i  through j (where i < j

10条回答
  •  醉话见心
    2020-12-07 10:36

    The Nexus plugin provides the Series type and an object, s1, of that type used like this:

    :4,8s/^/\=s1.next().' '/
    

    Nexus also comes with an s0 Series object that yields 0 as its first .next() result. Both s0 and s1 use a 1-step increment. All Series objects have a .reset() method which sets them back to their initiated value. New Series objects can be created like the following call:

    let s2 = Series(0, 2)
    

    which creates a 2-step object meeting your second request (yielding: 2, 4, 6, 8, etc.).

提交回复
热议问题