You are on page 1of 2

17/01/2020 In vi, how do I go to a particular line or word in a file?

INDIANA UNIVERSITY (HTTP://WWW.IU.EDU)

ARCHIVED: In vi, how do I go to a


particular line or word in a file?
This content has been archived (anlq), and is no longer maintained by
Indiana University. Information here may no longer be accurate, and links
may no longer be available or reliable.

You can go to a particular line or word in a file using vi (adxz) in several ways:

To make vi start at a particular line in a file, add +line_num to the command you use to start vi.
Replace line_num with the line number, for example:

vi +36 foo.c

If you're already in vi, you can use the goto command. To do this, press Esc , type the line number,
and then press Shift-g . If you press Esc and then Shift-g without specifying a line number, it
will take you to the last line in the file.

You can also use the ex command line to go to a line. (For information about the ex mode, see Use
the vi text editor (adxz)) For instance, if you wanted to go to line 14, you could press Esc and then
enter:

:14

To search forward for some text, use the / (forward slash) command. Press Esc and then enter
/pattern , replacing pattern with the text for which you want to search forward. For example, to
find every instance of the word "blimp", enter:

/blimp

To look for the next occurrence after the first, either press n or press / again and then press
Enter . To go back to a previous occurrence, press Shift-n . To search backwards in a file, use the
? command.

To see what line you're on at any time, press Ctrl-Shift-g . To number all lines, press Esc and
enter:

:set number

At Indiana University, for personal or departmental Linux or Unix systems support, see Get help for Linux
or Unix at IU (beqc).

Related documents

https://kb.iu.edu/d/adxw 1/2
17/01/2020 In vi, how do I go to a particular line or word in a file?

Use the vi text editor (adxz)

This is document adxw in the Knowledge Base.


Last modified on 2018-01-18 09:31:34.

Contact us

For help or to comment, email the UITS Support Center (https://mailform.kb.iu.edu/email.php?


cid=65).

CONNECT WITH NAVIGATION IT@IU SUPPORT & MORE


UITS
Home (/) About IT Chat with a consultant
    Menu (/d/menu) (http://it.iu.edu/about/) (http://ithelplive.iu.edu)
(http:/
(https:/
/www.facebook.com/iu.uits)
(http:/
/twitter.com/insideuits)
(https:/
/www.youtube.com/uitsatiu)
/plus.google.com/109054154815294782478)
About us (/d/line) IT staff AskIU
(https://uits.iu.edu/staff) (https://mailform.kb.iu.edu/e
Jobs in IT cid=1061)
(http://it.iu.edu/jobs/) One.IU
OVPIT (https://one.iu.edu)
(http://it.iu.edu/ovpit/)

Version: trunk

(H T TPS://200. I U. E DU )

(https://www.iu.edu)

Accessibility (https://accessibility.iu.edu/assistance) | Privacy Notice (/privacy)

Copyright (https://www.iu.edu/copyright/index.html) © 2019 The Trustees of Indiana University (https://www.iu.edu/)

https://kb.iu.edu/d/adxw 2/2

You might also like