About Linux FAQ

Browse More FAQs:

How To Show Line Numbers In vi / vim Text Editor

Posted by Vivek Gite [Last updated: May 12, 2008]

This FAQ is part 1 of 9 in the series 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

Navigation for VI / VIM Text EditorTurn on or off color syntax highlighting in vi or vim»

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:

Discussion on This FAQ

  1. yoander Says:

    Inside vim editor in command mode you can go directly to specific line pressing line number (ex: 50) and shift g.

  2. billyduc Says:

    THat’s really kool

  3. Planet Lowyat Says:

    Can VI display 3 desire lines such as line x(10), line y(25) and line z(50) only?

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!

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word

Tags: , , , , , , , ,

Copyright © 2006-2008 nixCraft. All rights reserved - TOS/Disclaimer - Privacy policy - Sitemap - Powered by Open source software.