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 “go to file” 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:
spec/models/order_spec.rb:126
spec/controllers/admin/user_controller_spec.rb:74
app/models/product.rb:35
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:
Also from the command line you can open a file at a given line with "+" - e.g. `vim file.txt +100` will open file.txt and jump to line 100.