tags:

views:

149

answers:

1

There is a vim variable with the string value like this:

foo%:p:r:sbar

%:p:r:s is a vim wildcard.

How can I expand all wildcards in the string variable?

Unfortunately expand(my_variable) doesn't help. Do I need to specify any additional argument or use other vim function?

Thanks.

+1  A: 

Try :help expand()

This section of the docs seems especially relevant to you:

            Modifiers:
                    :p              expand to full path
                    :h              head (last path component removed)
                    :t              tail (last path component only)
                    :r              root (one extension removed)
                    :e              extension only

            Example: >
                    :let &tags = expand("%:p:h") . "/tags"
            Note that when expanding a string that starts with '%', '#' or
            '<', any following text is ignored.  This does NOT work: >
                    :let doesntwork = expand("%:h.bak")
            Use this: >
                    :let doeswork = expand("%:h") . ".bak"

It looks like your trailing (and possibly leading) strings won't work with expand().

This does work though:

:echo "foo" . expand("%:p:r:s") . "bar"

Possibly you can rework your script so wildcards are expanded before they are combined with other strings. Alternatively you could try to split the concatenated string, expand the wildcards, then re-concatenate.

samg
I guess that by myself.I will have to refactor a lot of code in this case because the string is being generated dynamically by other vim function.Is there a way to do that in general?
Bogdan Gusiev