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

How do I open a file under the cursor in a new split and jump directly to the line number?

Answer

<C-w>F

Explanation

<C-w>F opens the filename under the cursor in a new horizontal split, and if the filename is followed by a colon and a number (e.g. src/app.go:42), Vim jumps directly to that line. This is the split-window companion to gF, and is invaluable when reading compiler errors, grep output, or stack traces that embed file paths with line references.

How it works

  • <C-w> — prefix for window (split) commands
  • F — open the file under the cursor in a new split, with line number support (uppercase F = with line jump)
  • The cursor scans forward from its position to find a filename pattern
  • If filename:N is detected, the cursor is placed on line N in the opened file
  • Compare with the related family:
    • gf — open in same window, no line number
    • gF — open in same window, with line number
    • <C-w>f — open in new split, no line number
    • <C-w>F — open in new split, with line number

Example

Your terminal shows a compile error:

src/parser.go:87: undefined: tokenize

With the cursor on that line (e.g. after :r !go build 2>&1), pressing <C-w>F opens src/parser.go in a new split and positions the cursor on line 87, ready to fix the error.

Tips

  • Use <C-w>gF to open in a new tab (with line number) instead of a split
  • Combine with <C-w>_ to maximize the new split after opening
  • Works with paths relative to the current working directory or anywhere in 'path'
  • Particularly useful after :make or :vimgrep when manually inspecting output

Next

How do I sort lines using only the text matched by a regex pattern as the sort key?