Move or Jump to Specific Lines in Vi

Posted February 16, 2004 by Rex in UNIX

Navigating large files is an important capability when using any editor. The vi editor makes provides a simple means to move around.


All of the following commands must be entered in command mode, not insert mode. Pressing ESC will ensure you are in command mode. If the commands are not working for you, you have made the common mistake of not entering command mode first.

To move to the end (last line) of a document, use the following:

G

To move to the first line of a document, use the following:

0G

This is a special case of the more general command to move to any specific line. To jump to the 3872nd line, for example, enter the following:

3872G

Additionally, you can jump directly to that line using the common syntax:

:3872

The Conversation

Follow the reactions below and share your own thoughts.