Move or jump to specific lines in vi

Contributor Icon Contributed by Rex Date Icon February 16, 2004  
Tag Icon Tagged: UNIX

Navigating large files is an important capability when using any editor. The vi editor makes it easy 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.

To jump to the end (last line) of a document:

G

To move to the first line of a document:

0G

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

3872G

Previous recipe | Next recipe |
 
  • Anonymous
    This can also be done using the ex facility of vi: simply type ":" (to get the ex prompt), then the line number, then return; ":0" goes to the first line; ":$" goes to the last. More keystrokes, but it syncs well with things like ":0,$s/foo/bar/g".
  • anon
    This doesnt work.
  • mgumgu
    Thanks for the very helpful info! Though i noticed that when i type 0G i still jump to the end of the file. But to go to the beginning i need to type 1G instead. Thought i should share. Cheers!
blog comments powered by Disqus