To insert line numbers at the beginning of every line in Vim, do this:
:%s/^/\=line(".")
This is a global search and replace (%s/[search]/[replace]), matching the beginning of each line (^) with an expression (\=) that returns the current line number (line(".")).
To add a comma (or any other character) after the line number, do it like this:
:%s/^/\=line(".") . ","
Any valid Vim expression is valid after the "\=", so you could start line number with 100 like this:
:%s/^/\=100+line(".")
Pretty simple and straightforward, when you think about it.
Set as favorite
Bookmark
Email This
Hits: 240
Comments (0)

Write comment
You must be logged in to post a comment. Please register if you do not have an account yet.