Open file to line

Quickly jump to a certain line on a given file

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:

Was this useful? Help us improve!

With your feedback, we can improve VimTricks. Click a link to vote: