Can I have vi numeric strings starting at 0

I often use the vi command

:set number 

I recently tried to align some data with a zero-based index with line numbers in vim that has an index based on 1. Is there a way for vi to start line numbering from 0 or more widely from any other starting point?

+7
editor vi
source share
1 answer

The @David comment made me work a bit with goose, eventually finding this link: Add line numbers to source code in vim

For my purposes, what I needed was not necessarily permanent numbering, but simply temporary. Quickly insert / delete line numbers, and then resort to standard numbering. In this case, I did not think to simply insert and then delete my own line numbering. The following works well. And the possibilities are endless for the numbering (see, for example, https://stackoverflow.com/a/3129/ )

 %!awk '{print NR,$0}' 

For your own vi-solution, to add numbers, then (from https://stackoverflow.com/questions/83301/... ), line numbers will be inserted below, and then a space:

 :%s/^/\=line('.').' '/ 

Then (thanks to Lance) https://stackoverflow.com/a/166268/how-to-store-create-string-command-in-javascript/232632#232632

 :%s/^[0-9]* // 

If there is something in vim that I am missing, this can do constant numbering based on 0, please let me know.

0
source share

All Articles