Open a File Directly at the Requested Line with Vi

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.

Share this:

Support CNX Software! Donate via cryptocurrencies, become a Patron on Patreon, or purchase goods on Amazon or Aliexpress

ROCK 5 ITX RK3588 mini-ITX motherboard
Subscribe
Notify of
guest
The comment form collects your name, email and content to allow us keep track of the comments placed on the website. Please read and accept our website Terms and Privacy Policy to post a comment.
0 Comments
oldest
newest
Boardcon Rockchip and Allwinner SoM and SBC products