For displaying line numbers in vi/vim we will need to set the number flag.
Necessary steps to display the line numbers in vi/vim:
1. Edit your file with vi <filename>
2. Press the : (colon sign). The sign will appear the bottom-left of your screen
3. Enter the command for setting the number flag
set number4. Now you will see the line numbers for your file.

To hide line numbers, press : (colon) and enter:
set nonumberNotice that the vi/vim will not save your option to display the line numbers.
To automatically display line numbers:
1. Navigate to your home directory.
2. Create a file named .exrc
3. Edit the file and add the line:
set numberFrom now on, the vi/vim editor will display line numbers by default.
Resources:
How to install vim
How to install nano
