Vi Tip of the Week: What line number am I on?

This is part of a series of tips on using Vi.  To see the complete series, click here.

If you are editing a file in vi, and you want to know what line number you are on, it’s very easy to find it: press Control-G, and the status line at the bottom of the screen will tell you!  See, for example, the following screenshot taken just after I pressed Control-G:

Vi: screenshot after pressing Control-G

As you can see, the status line displays the name of the file I am currently editing (in this case, Hamurabi.java), the line number that my cursor is currently on (line 30),  the total number of lines in this file (351), how far down into the file I am as a percentage (8% of the way through the file), and which column that my cursor is currently on (column 9).

Depending on which version of vi you are using, your status line may look slightly different. On both a Mac (where the above screenshot is from) and on a Debian Linux box, I see identical status lines.  However, with the version of vi on Fedora Linux, I don’t even need to press Control-G, as the status line always tells me which line and column I’m on:

In this case, the “30,9” indicates that my cursor is currently on line 30, column 9.  The “6%” on the right-hand side of the status line tells me that the top line displayed in my window is 6% of the way through the file.  If I press Control-G now, I get a little bit of additional information:

As with the Mac and Debian versions of vi, I am told the name of the file, how many lines in the file, and how far I am through the file.  It’s the same information, just presented slightly differently.