vim line numbers - how to have them on by default?
Solution 1
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.
Solution 2
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 :)
Solution 3
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.
Solution 4
Terminal > su
> password
> vim /etc/vimrc
Click here and edit as in line number (13):
set nu
Solution 5
I did not have a .vimrc file in my home directory. I created one, added this line:
set number
and that solved the problem.
Comments
-
Michael Durrant almost 2 years
I can
:set number
from within a file I'm editing but how can I have them always be on by default? -
Tim Pote about 12 yearsYeah. Any time I want to set some defaults for a command line program I search their man page for
rc
. It's a pretty common convention. -
abe312 over 8 yearsby sudo it will also work if folder is restricted, which is often the case.
-
Christian Brabandt over 8 yearsYes, and you break access for the normal user which owns his home directory. This has been the cause of several bug reports and is just the wrong solution
-
yonatan almost 8 yearsalso why use gedit? what if it's a server? or gedit is just not installed? make more sense to use vim :)
-
crobicha about 7 yearsNote that this would change default vim behavior for ALL users on a system, unless overridden by a users personal .vimrc in their home directory
-
Ryan Hoo over 6 yearsI like the color scheme in this screenshot, which one are you using?
-
Rajeev Ranjan over 5 yearsCreate the file .vimrc if it does not exist in the home directory.
-
Brosig over 5 yearsFor ubuntu server the file location is
/etc/vim/vimrc
-
aarona about 5 yearsanother great setting that's useful is
set relativenumber
-
Kapil Jituri over 4 yearsSimply run this command anywhere in your terminal:
echo "\nset nu" >> ~/.vimrc
. Now exit and reopen terminal session. -
unknown programmer guy over 3 yearsif you cant find .vimrc in your home directory, you can check it inside /etc/vim/vimrc
-
maruf over 2 yearsThis works but maybe VIM's default profile no longer working. One example: After creating .vimrc file java's default documentation comment's formatting not working correctly :(