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
You should follow me on twitter here or grab rss feed to keep track of new changes.
Featured Articles:
- 30 Handy Bash Shell Aliases For Linux / Unix / Mac OS X
- Top 30 Nmap Command Examples For Sys/Network Admins
- 25 PHP Security Best Practices For Sys Admins
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- Linux: 20 Iptables Examples For New SysAdmins
- Top 20 OpenSSH Server Best Security Practices
- Top 20 Nginx WebServer Best Security Practices
- 20 Examples: Make Sure Unix / Linux Configuration Files Are Free From Syntax Errors
- 15 Greatest Open Source Terminal Applications Of 2012

- My 10 UNIX Command Line Mistakes
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- The Novice Guide To Buying A Linux Laptop












{ 32 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.
Works with vi & vim in Centos 6.3
noarch:printing-4.0-amd64:printing-4.0-noarch
Distributor ID: CentOS
Description: CentOS release 6.3 (Final)
Release: 6.3
Codename: Final
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
thank you for this info. My vim is look more beautiful :)
this is why I like vim
Thanks!
This works in Poderosa too. Anyone know how to just turn on a display at the bottom of the screen that shows which line you’re on, as an alternative to having all the rows numbered? Poderosa does this on my Dreamhost account but not on another site I use, don’t know why.
I have been to your site before and was back again searching for displaying the line numbers. Thank you for this quick bit of help.
it’s helpful for beginners,thx
Thanks
Thanks, Its working.
How can i get current cursor number in vi editor???
launch vi –> vi ENTER
type –> :set number ENTER
Now as you press down or up, you will see the number value change on the bottom right.
.vimrc not available at ~/
now where should I add “set number”
@newbee: Are you using a Debian-based system? If so, .vimrc is not included in your home dir. You can create the file by doing this at your command prompt:
You’ll then be inside the vi editor. Press “i” for insert mode and type “set number” into the first line of the editor.
Once you are done, press ESC, then type ZZ and press Enter. You’ll automatically write the file and exit to your command prompt. You’ll now see .vimrc in your home dir.
You should now be able to see line numbers when you vi a file.
Last edited by Admin; 24th Feb 2013 at 9:59 AM. Reason: Correction.
You solve my problem in shortest waythat possible.
thank you
tnks really useful ……….