brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: gf in Vim opens the file whose name is under the cursor

Vim
~/tips/tip-vim-gf-open-file

gf

Opens a path from your text without typing it.

A config file that includes another one, a log line with a path, a list of files in a README: if the name is under your cursor, Vim can open it.

gf

gf stands for goto file. It takes the word under the cursor as a file name and opens it in the current window. Relative names are looked up in the folders listed in the path option, which by default includes the folder of the current file and the folder you started Vim in.

To come back, use Ctrl-o or Ctrl-^, which switches to the previous file.

Two variants I like:

Ctrl-w f
gF

Ctrl-w f opens the file in a new split, and gF also jumps to the line number after the name, so app.py:42 takes you straight to line 42. That second one is great for compiler errors and stack traces.

If the current file has unsaved changes, gf refuses to leave it unless hidden is set. Save first, or put set hidden in your vimrc. Also, what counts as part of a file name follows the isfname option, so names with spaces won’t work.

Further reading: Vim help: gf, Vim help: 'path'

Going deeper: Guide: advanced tmux, a config that grows with you, formats, layouts and more

More Vim tips :%s/<Ctrl-r><Ctrl-w>/newname/g /oldname find . -name "*.conf" | vim – vim --clean file.txt :set textwidth=72 All Vim tips (45) All topics

Link