Vim Recipes ‣ Display ‣ Displaying Line Numbers
You want to see each line's number alongside it. For example, if you’re writing a program, error messages frequently reference line numbers.
Use :set number to enable line numbering. If you're using a small monitor, you may want to disable them: :set nonumber.
Even if you're not programming, line numbers can still be useful. For example, if you’re collaborating on a file with other people, they may mention specific lines, which you can then jump to with :number. If you’re wrapping long lines, the line number can be used to differentiate the beginning of the line from the point at which it has been wrapped.
By default the number column is at least 4 characters wide, regardless of how many lines the file has. To change this minimum width use :set numberwidth=width.
The line numbers are only displayed when you’re viewing the file with Vim; the actual file isn't modified. If you'd like it to be, and you have the cat command on your system, you can execute :%!cat -n %. This filters the entire file through cat and prepends the number to each line.
Lastly, if you'd like to see the line numbers when you print the file without permanently changing its contents: :set printoptions=number:y.