I am using following code (from somewhere on the net but I forgot the page) to add line numbers to text files:
:%s/^/\=printf('%d] ' , line('.'))/g
I have tried to modify it to accept ranges:
command -range=% Addln <line1>,<line2>s/^/\=printf('%d] ' , line('.'))/g
It works for whole file all right, but when I try to apply it to a selection, it adds line numbers starting from file line number and not 1. How can I change it so that it adds line numbers to the selection starting from 1? Thanks.