I often use gf in vim to open files under cursor. Often these file paths use environment variables. When the environment variable is used without curly braces, vim has no trouble understanding it. But when curly braces are used, vim is unable to use the environment variable value.
This works for gf:
$tools/tools.json
This does NOT work for gf:
${tools}/tools.json
Is there a way to make vim understand the curly braces syntax for environment variables? FYI, I am on Linux (SLES11SP3) in a TCSH shell, Vim 8.0.
The isfname setting specifies the set of characters that can appear in file names. It does not include { and } by default.
The default setting for most systems is:
isfname=@,48-57,/,.,-,_,+,,,#,$,%,~,=
If you change it to:
isfname=@,48-57,/,.,-,_,+,,,#,$,%,~,=,{,}
then the gf command will recognize ${tools}/tools/json as a single file name.
Adding
set isfname+={,}
to your .vimrc should do the trick.
You need to add these two lines to your .vimrc file:
set isfname+={,}
set includeexpr=substitute(v:fname ,'\v\$\{(\w+)}','$\1','g')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With