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

前端 未结 10 2041
野趣味
野趣味 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:16

    :4,8s/^/\=line(".")-3." "    
    

    will do what you want

    if you need count=2:

    :4,8s/^/\=2*(line(".")-3)." " 
    

    this will give you 2,4,6,8,10

    line numbers are hard coded in my example, you could use V to select those lines you want to change.

提交回复
热议问题