2

If there is no variable in path, gf can open the file.
Added sfname+={,} to .vimrc to support ${VARIABLE}.
:!echo ${VAR}/test/file can correctly print full path with ${VAR} expanded.
But if run 'gf' on it, it gives error: E447: Can't find file "${VAR}/test/file" in path
How to fix this?

  • 3
    According to :h expand-env and :h gf, environmental variables are expanded in the form $HOME. Can you use this form instead of ${HOME}? Otherwise you will need to probably use 'includeexpr' and a substitution (substitute('${HOME}/test/file', '\${\([^}]*\)}', '\=expand("$".submatch(1))', 'g')) – Peter Rincker Aug 23 '18 at 20:04
  • 2
    @PeterRincker want to turn that into a real answer? – D. Ben Knoble Aug 24 '18 at 2:21
  • @PeterRincker, now ${HOME} is working, but other variable name as ${ROOT} is still not working. – Fisher Aug 24 '18 at 9:49
  • @PeterRincker, found the reason, need to define variable as let $ROOT = '/full/path'. Can't define it as let $ROOT = '~/path'. After $ROOT is defined and the expanded path is valid, I can gf goto the file. – Fisher Aug 24 '18 at 10:14

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.