How To Show Line Numbers In vi / vim Text Editor
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
Subscribe to our free e-mail newsletter or RSS feed to get all updates.
You can Email this page to a friend.
Related Other Helpful FAQs:
- Linux Firewall: Display Status and Rules of Iptables Firewall
- vi / vim Print Line Numbers on Hardcopies / Printer
- Shell Script To Number Lines Of Files
- Linux / UNIX find out what other users are doing?
- Linux: find out information about current domain name and host name
Discussion on This FAQ
Leave a Reply
We encourage your comments, and suggestions. But please stay on topic, be polite, and avoid spam. Thank you very much for stopping by our site!
Tags: c program, display vi line nymber, line numbers, readability, shell script, vim, vim off line number, vim on line number, vim text editor



May 12th, 2008 at 2:27 pm
Inside vim editor in command mode you can go directly to specific line pressing line number (ex: 50) and shift g.
May 13th, 2008 at 10:15 am
THat’s really kool
May 17th, 2008 at 4:20 pm
Can VI display 3 desire lines such as line x(10), line y(25) and line z(50) only?