# someone have some code to number lines

4 messages
Open this post in threaded view
|

## someone have some code to number lines

 I need to number lines. Ex:  I have aaaa bbbbb cccc dddd ... I need to do 1 aaaa 2 bbbbb 3 cccc 4 dddd or 4 aaaa 3 bbbbb 2 cccc 1 dddd Need to supply a range (via Shift v) The supply a numbering range 1-4 or 4-1 I have to do this constantly.  Most of the time it's between 16 and 64 lines.  I have files that contain only these nubers in a column but would like a more automated method. --     ___  _ ____       ___       __  __    / _ )(_) / /_ __  / _ \___ _/ /_/ /____  ___   / _  / / / / // / / ___/ _ `/ __/ __/ _ \/ _ \ /____/_/_/_/\_, / /_/   \_,_/\__/\__/\___/_//_/             /___/ Texas Instruments ASIC Circuit Design Methodology Group Dallas, Texas, 214-480-4455,  [hidden email]
Open this post in threaded view
|

## Re: someone have some code to number lines

 > Need to supply a range (via Shift v) > The supply a numbering range 1-4 or 4-1 The common way is to use the expression stuff as described at :help sub-replace-special :he eval.txt :he line() For a simple example, it would be something like :%s/^/\=line(".")." " which will simply insert the current line number at the beginning of each line in the range. For more complex work, beginning counting at one, but starting on something *other* than the first line would be something to the following: :'<,'>s/^/(1+line(".") - line("'<"))." " For doing inverted line numbering, you'll have to do inverting math.  Something like :'<,'>s/^/\=(1+line("'>") - line("."))." " These can easily be mapped as needed. HTH, -tim