vim line numbers - how to have them on by default?
set nu
set ai
set tabstop=4
set ls=2
set autoindent
Add the above code in your .vimrc file. if .vimrc file is not present please create in your home directory (/home/name of user)
set nu -> This makes Vim display line numbers
set ai -> This makes Vim enable auto-indentation
set ls=2 -> This makes Vim show a status line
set tabstop=4 -> This makes Vim set tab of length 4 spaces (it is 8 by default)
The filename will also be displayed.
Add set number
to your .vimrc
file in your home directory.
If the .vimrc
file is not in your home directory create one with
vim .vimrc
and add the commands you want at open.
Here's a site that explains the vimrc and how to use it.
To change the default setting to display line numbers in vi/vim:
vi ~/.vimrc
then add the following line to the file:
set number
Either we can source ~/.vimrc
or save and quit by :wq
, now future vi/vim sessions will have numbering :)