In Javascript is very common to have rootPath/rootURL import to avoid long ../../../../, like:

import PageFoo from '~/pages/foo/';

//instead of
import PageFoo from '../../../../pages/foo/';

When the cursor is on ../../../../pages/foo/, I'm able to open the file using gf command, but it doesn't work on ~/pages/foo.

How can I go to file using gf with ~/pages/foo ?

  • :help gf says For Unix the '~' character is expanded, like in "~user/file". Environment variables are expanded too |expand-env|. However I suspect this means that vim is looking for exactly the file ~/pages/foo.js, and you want to look for project-root/pages/foo.js? – D. Ben Knoble Jan 22 at 14:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.