Open file to line


You may already know about that you can open a file based on what’s under your cursor using gf, or ctrl-w f. I like to use gf and remember the handy mnemonic “ g o to f ile” and it’s one of the primary ways I navigate projects in Vim.

But lesser known is a handy variation on this using capital F. This variation will open the file under your cursor, but if it’s followed by a line number Vim will jump to that line. One place you might encounter this if you’re running tests in Vim with Dispatch.

Say you’re in a log file which contains file references:


With your cursor sitting anywhere on a line containing the file name, use gF. You’ll be transported to the file and land exactly on the line referenced after the colon, saving you from having to navigate down to that line separately. Saving steps is saving time. Here’s a very short screencast to demonstrate:

How useful was this tip?

Average rating 3.4 / 5. Vote count: 270

No votes so far! Be the first to rate this tip.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?

Written by

Colin Bartlett

105 Posts

Vim enthusiast and software developer for more than 20 years.
View all posts