16

In vi editor how do I go to a particular line ?

For example if I open a file named file.py is there an option for open the file at a particular line or can I open my file and then go to line with keybord shortcut ?

  • 1
    You are welcome here and got your answer. Just an advice for the future: With man vi you can read the manual page. With /line you can search for occurences of the word line, with n jump to the next one, just like in vi. One of the first matches describes the option you were looking for. This takes less time than searching the web or asking a question here. – Philippos Sep 10 '18 at 15:23
26

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 +14 file.py

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) For instance, if you wanted to go to line 14, you could press Esc and then enter:

:14

There is also a vi command. The G jump motion takes an optional count prefix, which is the line number to go to. Hence 1 4 G

| improve this answer | |
  • ...and you'd only press ESC if you weren't already in command mode (or you like your screen to flash) – Jeff Schaller Sep 10 '18 at 14:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.