Displaying line numbers under vi / vim can be very useful for debugging program errors and to improve overall readability of a program or scripts.
Vi or 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. First press the Esc key. Press : and type any one of the following command at a : prompt:
To turn off (or hide) line number again enter the same command at the : prompt:
If you need number every time you start vi/vim, append the following line to your ~/.vimrc file:
Append the following line:
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
How do I list of all current settings?
At the : prompt, enter:
To see a list of everything that you have set so far in your vim config file or runtime, type the following command at the : prompt: