Home > Linux > Open a File Directly at the Requested Line with Vi

Open a File Directly at the Requested Line with Vi

September 22nd, 2011 Leave a comment Go to comments

When you compile a program and an error occur, the compiler will report the file name and line number with the error.

Usually, I use vi to access the file, then type “:line_num”, for example if I want to jump to line 123, I would type :123 after opening the file.

But there is a way to do that directly with vi by using +line_num. For example:

 vi +123 code.c

To go to the last line, I would normally use the capital letter G when vi is started, but this can be done while opening the file as follows:

vi +$ code.c

One last tip: To go back at the top of the file in vi, simply use :0 or the capital letter H.

  1. No comments yet.
  1. No trackbacks yet.