Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[vim] expand 'environment variable like' variables

139 views
Skip to first unread message

Alessandro Basili

unread,
Jan 6, 2017, 5:28:35 AM1/6/17
to
Hi everyone,

I have the following text in a configuration file:

-f ${PROJ}/tb/hdl/stimuli/stimuli.args¬

where $PROJ is an environment variable but needs to be passed with braces otherwise the tool does not expand it correctly.

Now in vim I know that gf can follow the file and expand environment variables known to vim, but in this case it will fail because it does not know how to expand the variable in the braces.

Any idea on how to do it?

I've thought about a remap that would grab the full text between spaces, strip out the braces and then apply gf to it, but it's easier to say than to do it :-/.

Thanks for any input,

Al

--
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?

Eli the Bearded

unread,
Jan 6, 2017, 4:50:39 PM1/6/17
to
In comp.editors, Alessandro Basili <al.b...@gmail.com> wrote:
> -f ${PROJ}/tb/hdl/stimuli/stimuli.args¬

Looks like corrupt unicode there to me.

> where $PROJ is an environment variable but needs to be passed with
> braces otherwise the tool does not expand it correctly.
...
> Any idea on how to do it?

Add { and } to isfname and it works for me:

:set isfname
isfname=@,48-57,/,.,-,_,+,,,#,$,%,~,=

:set isfname=@,48-57,/,.,-,_,+,,,#,$,%,~,=,{,}

Then 'gf' tries to open the whole thing starting at the "${", and since
it is an environment variable, it expands as expected.

Elijah
------
you might want unicode in that if you are using it in filenames though

alb

unread,
Jan 7, 2017, 11:08:39 AM1/7/17
to
Eli the Bearded <*@eli.users.panix.com> wrote:
> Add { and } to isfname and it works for me:
>
> :set isfname
> isfname=@,48-57,/,.,-,_,+,,,#,$,%,~,=
>
> :set isfname=@,48-57,/,.,-,_,+,,,#,$,%,~,=,{,}
>
> Then 'gf' tries to open the whole thing starting at the "${", and since
> it is an environment variable, it expands as expected.

That works like a charm! Thanks a lot.
For the time being I will add those chars to the isfname for every file, but
since I will most likely incur into this situation only on *.args file I could
do something like this:

function! toggleisfname
if &ft = 'args'
set isfname=@,48-57,/,.,-,_,+,,,#,$,%,~,=,{,}
else
set isfname=@,48-57,/,.,-,_,+,,,#,$,%,~,=
endfunction

That would imply that I will set the args filetype everytime I am in an *.args
file.

>
> Elijah
> ------
> you might want unicode in that if you are using it in filenames though

Eli the Bearded

unread,
Jan 9, 2017, 7:39:26 PM1/9/17
to
In comp.editors, alb <al.b...@gmail.com> wrote:
> For the time being I will add those chars to the isfname for every file, but
> since I will most likely incur into this situation only on *.args file I could
> do something like this:
>
> function! toggleisfname
...

autocmd BufRead *.args :set isfname=@,48-57,/,.,-,_,+,,,#,$,%,~,=,{,}

Or get fancier, and ':source' a file with settings. I do that for the
mail and post files created by my newsreader, to set my news reply
defaults.

Elijah
------
has various de-smart-quote map!s and such
0 new messages