- How To Show Line Numbers In vi / vim Text Editor
- Turn on or off color syntax highlighting in vi or vim
- Ubuntu Linux Vim Sorry, the command is not available in this version: syntax on
- UNIX / Linux: vi / vim perform search and replace operation
- FreeBSD install VIM text editor
- vi / vim Print Line Numbers on Hardcopies / Printer
- vi / vim Auto complete File Name While Editing Files
- Moving Around With vim (keyboard short cuts)
- How do I Be More Productive In Vim?
- Vim Editing Multiple Files and Windowing Support Under Linux / UNIX
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
- My 10 UNIX Command Line Mistakes
- 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
- Email FAQ to a friend
- Download PDF version
- Printable version
- Comment RSS feed
- Last Updated: 05/12/08


{ 8 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.