Friday, August 13, 2010

Re: use the variable

On 2010-08-13, eliweiq001 wrote:
> suppose I have such sentences in vimrc:
>
> source .\mydir\aaa.vim
> set xxxdir=.\mydir
>
>
>
> and if now I add a new a variable
>
> let yyy = ".\mydir"
>
>
> Now can I use the variable yyy instead of .\mydir in the sentences
> above ? How ?

The command to help you do this is :execute, which can be
abbreviated to :exe. See

:help :execute

For example, your two commands above could be written as

exe "source " . yyy . "\aaa.vim"
exe "set xxxdir=" . yyy

Since the backslash (\) is also used to escape or quote the
character following, you may have to use \\ instead of just \ or
enclose the string containing \ in single-quotes (') instead of
double-quotes ("). (I didn't test the first command to see.) It is
often safest to use forward slashes (/) instead of backslashes to
separate directories in a path, even when using Vim on Windows. Vim
knows how to translate them to backslashes before giving the string
to a Windows command and you avoid the quoting issues.

An alternative way to set Vim options is to use :let instead of
:set, as described here:

:help :let-&

Your second command could then be written as

let &xxxdir = yyy

Regards,
Gary

--
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: