How do I open a file under the cursor in a new split and jump to its line number in Vim?
Answer
<C-w>F
Explanation
<C-w>F opens the filename under the cursor in a new horizontal split window and jumps to the line number that follows the filename. This makes it ideal for navigating stack traces, compiler error output, or any text where filenames appear alongside line numbers (e.g. src/main.c:42).
How it works
<C-w>Fis the uppercase variant of<C-w>f- Like
<C-w>f, it opens the file under the cursor in a new horizontal split - Unlike
<C-w>f, it also parses the line number that immediately follows the filename in the formfilename:linenoorfilename(lineno), and positions the cursor at that line
Example
Given a compiler error logged in a buffer:
src/parser.c:87: error: undeclared identifier 'tok'
With the cursor anywhere on src/parser.c:87, pressing <C-w>F will:
- Open
src/parser.cin a new split - Jump to line 87
Compare with the related commands:
<C-w>f — open file in split (no line number)
gF — open file + line number in current window (no split)
<C-w>gF — open file + line number in new tab
Tips
- Vim uses the
pathoption to resolve relative filenames, so set:set path+=src/**if needed - For filenames without a line number,
<C-w>Ffalls back to opening the file at line 1 - Use
:set suffixesadd+=.c,.hto help Vim find files without explicit extensions