Cyprich.com

Occasionally Relevant Insights from a Software Builder

By

Using Line Numbers in vi

Debugging is easier with line numbers. The default setting for vi and vim is for line numbers in the document to be hidden.

Setting Line Numbers within the Editor

You can turn on line numbers by typing

:set number

or

:set nu

 

The line numbers can also be turned off by typing

:set nonumber

or

:set nu!

 

Making Line Numbers Default in vi

You need to edit .vimrc or .bashrc (which is normally found in the root of the user’s folders). Add the following command:

set number

vi will start with line numbers every time a document is opened.

 

Jump to a Line When Opening vi

If you know which line you would like to edit in vi, you can go right to the line when you open the document in vi from the shell.

$ vi +linenumber file.php

i.e. vi +8 file.php will open the document and place the cursor in line 8.

Leave a Reply

Your email address will not be published. Required fields are marked *