How to Add Line Numbers to Vim Permanently

Recently I’ve started working with a VM and I realized that debugging was a bit hard because I couldn’t see the line numbers for the code, so I searched up how you can see line numbers in vim, and found that when you are in a file with vim, press ESC, then enter the command:

:set number

The line numbers will show up. Yet, if you quit out of that session, and vi into the file again, you will see that the line numbers are gone. In order to set line numbers permanently in vim, you would need to go into your ~/.vimrc file and set properties for vim, but I noticed that in the VM I was on, there were no other directories or that file, so I created that file in my home directory by doing:

cd ~ 
vim .vimrc
set number
:wq

1st command: goes to home directory

2nd command: creates .vimrc file

3rd command: adds “set numbers” property into vimrc

4th command: saves and quits out of file

Leave a Reply

Your email address will not be published.