How to add line numbers to VI by default

I am running on Snow Leopard 10.6.6. at the time of this post.  VI is a handy tool to use because it is installed on every single non-windows box I have ever seen.  I originally only used nano and I have found out that nano is not everywhere.

1) you need to locate your .vimrc file, on osx I just did a locate vimrc and got this

bash-3.2# locate vimrc
/opt/local/var/macports/sources/rsync.macports.org/release/ports/editors/vim-app/files/gvimrc
/opt/local/var/macports/sources/rsync.macports.org/release/ports/editors/vim-app/files/vimrc
/usr/share/vim/vim72/gvimrc_example.vim
/usr/share/vim/vim72/vimrc_example.vim
/usr/share/vim/vimrc

2) now just vi open that file

I did a vi /usr/share/vim/vimrc and then added the line set number to the end here is how my file looks->

" Configuration file for vim 
set modelines=0         " CVE-2007-2438

" Normally we use vim-extensions. If you want true vi-compatibility
" remove change the following statements
set nocompatible        " Use Vim defaults instead of 100% vi compatibility
set backspace=2         " more powerful backspacing

" Don't write backup file if vim is being called by "crontab -e" 
au BufWrite /private/tmp/crontab.* set nowritebackup
" Don't write backup file if vim is being called by "chpass"
au BufWrite /private/etc/pw.* set nowritebackup

set number

3) now quit and save, everytime you open vi it will show line numbers, to turn them off you can do a :set nonumber

4 Replies to “How to add line numbers to VI by default”

  1. Almost helpful. You skip from find the file to here is how it looks after adjustment.

    Why not show the actual adjustment? That would be thoroughly helpful. I need to go search for the actual adjustment now…

  2. While I’m marring up the comments I may as well mention something useful!
    On OpenSUse 11.4 I found, among all the vimrc and .vimrc files found I had to edit only: vi /etc/vimrc

    And now all is well and numbers show.

Leave a Reply to Neil Cancel reply

Your email address will not be published. Required fields are marked *

*