In vi, how do I go to a particular line or word in a file? (2024)

This content has been archived, 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 fileusing vi 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. Replaceline_num with the line number, for example:
     vi +36 foo.c
  • If you're already in vi, you can use the goto command. To dothis, press Esc, type the line number, and then pressShift-g. If you press Esc and thenShift-g without specifying a line number, it will takeyou to the last line in the file.
  • You can also use the ex command line to go to a line. (Forinformation about the ex mode, see Use the vi text editor) For instance, if you wanted to go to line 14, you couldpress Esc and then enter:
     :14
  • To search forward for some text, use the/ (forward slash) command. PressEsc and then enter /pattern, replacingpattern with the text for which you want to searchforward. For example, to find every instance of the word "blimp", enter:
     /blimp
    To look for the next occurrence after the first, either pressn or press / againand then press Enter. To go back to a previousoccurrence, press Shift-n. To search backwards ina file, use the ? command.
  • To see what line you're on at any time, pressCtrl-Shift-g. To number all lines, pressEsc 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.

Related documents

This is document adxw in the Knowledge Base.
Last modified on 2018-01-18 09:31:34.

In vi, how do I go to a particular line or word in a file? (2024)
Top Articles
Latest Posts
Article information

Author: Laurine Ryan

Last Updated:

Views: 6411

Rating: 4.7 / 5 (57 voted)

Reviews: 80% of readers found this page helpful

Author information

Name: Laurine Ryan

Birthday: 1994-12-23

Address: Suite 751 871 Lissette Throughway, West Kittie, NH 41603

Phone: +2366831109631

Job: Sales Producer

Hobby: Creative writing, Motor sports, Do it yourself, Skateboarding, Coffee roasting, Calligraphy, Stand-up comedy

Introduction: My name is Laurine Ryan, I am a adorable, fair, graceful, spotless, gorgeous, homely, cooperative person who loves writing and wants to share my knowledge and understanding with you.