Q. How do I display vi / vim text editor line numbers while writing a shell script or c program? How can I turn on or off this feature?
A. Displaying line numbers under vi / vim can be very useful for debugging code errors and to improve overall readability of a program.
vi / vim show line number command
To display line numbers along the left side of a window, type any one of the following:
:set number
or
:set nu

(Fig.01: Vi / Vim line numbers in action - click to enlarge image)
To turn off line number again enter the same command:
:set nu!
If you need number every time you start vi/vim, append following line to your ~/.vimrc file:
set number
Save and close the file.
Jump to particular line number from a shell prompt, enter:
$ vi +linenumber file.c
$ vi +300 initlib.c
Featured Articles:
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- My 10 UNIX Command Line Mistakes
- Linux: 20 Iptables Examples For New SysAdmins

- 25 PHP Security Best Practices For Sys Admins
- The Novice Guide To Buying A Linux Laptop
- 10 Greatest Open Source Software Of 2009
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- Top 20 OpenSSH Server Best Security Practices
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Linux Video Editor Software
Facebook it - Tweet it - Print it -


{ 17 comments… read them below or add one }
Inside vim editor in command mode you can go directly to specific line pressing line number (ex: 50) and shift g.
THat’s really kool
Can VI display 3 desire lines such as line x(10), line y(25) and line z(50) only?
Hi,
The “:set number or :set nu” is working great in VI.
Thank you!
Dean
Thanks you so much!
it works!
its working.
Thanks!
hilmy
Or colon, line number, and Enter (e.g. :50 [enter]). It does the same thing, but is my personal preference over the 50G option.
Does not work in gvim with vim6.3 in centOS.
I use Debian you need to create .vimrc in your home directory for that.
Also syntax on will help
thank uuuuuuuuuuuuu.hehe
Previous post not properly added
Hi,
vi “file name” +
vi + will open the file and cursor will be at specified line.
If the format is
vi “file name” :
vi : – How can I get the same behavior.
thnx
-Venu
exactly what i was looking for. thank you.
Thanks
this is great tutorial. I can see line number in my vim editor. thanks
its working .thx
thanks
You can also add:
set number
~/.vimrc