vimtricks.wiki Concise Vim tricks, one at a time.

How do I open the file under the cursor and jump to a specific line?

Answer

gF

Explanation

The gF command opens the file under the cursor and jumps to the line number that appears after the filename. This is useful for navigating error messages and stack traces.

How it works

  • gF is like gf but also parses a line number after the filename
  • Recognizes patterns like file.py:42 or file.py line 42
  • Opens the file and positions the cursor on that line

Example

With a stack trace line:

File: src/main.py:142 - TypeError

With the cursor on the path, gF opens src/main.py and jumps to line 142.

Tips

  • gf opens the file but does not handle line numbers
  • <C-w>gF opens the file in a new tab page
  • <C-w>F opens it in a new split with the line number
  • Add directories to :set path to help Vim find files

Next

How do you yank a single word into a named register?