Open file to line
You may already know about that you can open a file based on what’s under your cursor using
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:
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:
We are sorry that this post was not useful for you!
Let us improve this post!
Tell us how we can improve this post?