How To Show Line Numbers In vi / vim Text Editor

How do I display vi / vim text editor line numbers while writing a shell script or c program? How can I turn on or off this feature on Linux, Apple OS X, or Unix-like operating systems?

Displaying line numbers under vi / vim can be very useful for debugging code errors and to improve overall readability of a program or scripts.

Vi / Vim show line number command

To display line numbers along the left side of a window, type any one of the following command while using text editor:
:set number
or
:set nu
Sample outputs:

Fig.01: vi/vim in action with line numbers
Fig.01: vi/vim in action with line numbers

To turn off line number again enter the same command:
:set nu!
If you need number every time you start vi/vim, append following line to your ~/.vimrc file:
vi ~/.vimrc
Append the following line:
set number
Save and close the file.

Tip: Open a file at particular location/line number

Jump to particular line number from a shell prompt, enter:
$ vi +linenumber file.c
$ vi +300 initlib.c

Jump to particular line that contains main() function from a shell prompt, enter:
$ vi +/searchTermHere file.c
$ vi +/main initlib.c
### note shell escape done with \ ###
$ vi +/addUser\( initlib.c
$ vi +/addUser\(arg1\) initlib.c