Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make vim understand environment variables using curly braces

Tags:

vim

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.

like image 520
shikhanshu Avatar asked Oct 26 '25 14:10

shikhanshu


2 Answers

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.

like image 60
Keith Thompson Avatar answered Oct 28 '25 02:10

Keith Thompson


You need to add these two lines to your .vimrc file:

set isfname+={,}
set includeexpr=substitute(v:fname ,'\v\$\{(\w+)}','$\1','g') 
like image 22
Meninx - メネンックス Avatar answered Oct 28 '25 04:10

Meninx - メネンックス



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!