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

How do I make @ characters count as part of filenames for gf and path motions?

Answer

:set isfname+=@-@

Explanation

gf is fast until it stops exactly at characters common in modern import paths, especially @ in scoped package names (@org/pkg/file). By default, Vim may treat @ as a delimiter, causing file-under-cursor motions to capture only part of the path. Extending isfname fixes that at the tokenizer level so navigation commands operate on the full reference.

How it works

  • isfname defines which characters are considered part of a filename
  • :set isfname+=@-@ appends @ as a valid filename character
  • After this, motions and commands that rely on filename parsing (gf, gF, <C-w>f, include jumps) can consume scoped paths correctly
  • The change is global; use :setlocal variants in filetype autocmds if you want scoped behavior

Example

Consider this JavaScript import:

import { x } from "@acme/tools/src/format";

With default parsing, gf on the path may stop at acme/tools/... or fail to capture the full token depending on cursor position. After:

:set isfname+=@-@

gf treats @acme/tools/src/format as one filename candidate, making jumps consistent on scoped package paths.

Tips

  • Inspect current value with :set isfname? before changing it
  • Pair with suffixesadd for ecosystems where imports omit extensions
  • If a language needs additional path characters, append them explicitly rather than replacing the whole option

Next

How do I execute a macro while ignoring custom mappings that could change behavior?