add line number in a file using vim

I just needed to insert line numbers in a file in vim. Thanks to I now know how to do this by replacing the start of every line using the following command: :%s/^/\=printf("%4d: ", line('.')) which adds the current line number formatted to 4 characters with leading spaces.