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

前端 未结 10 2047
野趣味
野趣味 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条回答
  •  萌比男神i
    2020-12-07 10:42

    Starting with Vim 8.0 one can use g Ctrl-a, see :help v_g_CTRL-A

    Go to line #4, use Ctrl-v to blockwise select the first character, go down 4 lines, press Shift i, enter 0 (this is 0, followed by Space) and Esc to exit insert mode.

    Now use gv to re-select the previously selected area. Press g Ctrl-a to create a sequence.

    I start with a 0 here, so I can re-select by gv. If you start with a 1, you need to re-select by hand while omitting the first 1.

    Use 2g Ctrl-a to use a step count of 2.


提交回复
热议问题