How do I open the file whose name is under the cursor in a new tab?
Answer
<C-w>gf
Explanation
<C-w>gf reads the filename under the cursor and opens it in a new tab page, keeping your current buffer untouched. It is the tab-based counterpart to gf (open in same window) and <C-w>f (open in a new split).
How it works
<C-w>— the window command prefixgf— go to file under cursor- Combined:
<C-w>gfopens the file in a new tab - If a line number follows the filename (e.g.
config.lua:42), use<C-w>gFto open the file at that exact line - Vim searches the
pathoption and the current working directory to locate the file
Example
Your init.lua contains:
require('plugins/telescope')
Place the cursor on plugins/telescope and press <C-w>gf. Vim opens plugins/telescope.lua (or similar, based on path and suffixesadd) in a new tab, so you can edit both files side by side across tabs.
Tips
- Add
set path+=**to your vimrc so Vim searches recursively under the current directory set suffixesadd=.lua,.py,.jshelps Vim auto-append extensions when the filename has none- Use
<C-w>fwhen you prefer a horizontal split, or:vertical <C-w>ffor a vertical split - After opening, switch back with
gT(previous tab) and forward withgt(next tab)