Sunday, March 6, 2011

Re: How to access to the string inside a string variable in a :e command

On Sun, 6 Mar 2011, Tim Chase wrote:

> On 03/06/2011 01:29 PM, Jean Johner wrote:
>> let foobar = "test2.f"
>>
>> Using
>> echo foobar
>> results in test2.f (OK)
>> Now I want to open test2.f
>> :e foobar
>> opens a file foobar
>> :e 'foobar'
>> opens the file 'foobar'
>> What is the syntax to open test2.f using the foobar variable.
>
> You have to build the string and execute it:
>
> :exec 'e ' . foobar

You should also protect "special" characters in foobar:

:exec 'e '.fnameescape(foobar)

This allows foobar to be a filename containing a space, for example.
(More details at :help fnameescape() -- some other Vim commands have
other characters with special significance.)

--
Best,
Ben

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments: