use the variable

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

use the variable

livim
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 ?

Thanks!

--
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
Reply | Threaded
Open this post in threaded view
|

Re: use the variable

thinca
let &xxxdir = yyy

:help expr-option

--
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
Reply | Threaded
Open this post in threaded view
|

Re: use the variable

Gary Johnson-4
In reply to this post by livim
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
Reply | Threaded
Open this post in threaded view
|

Re: use the variable

Nikolay Aleksandrovich Pavlov
Ответ на сообщение «Re: use the variable»,
присланное в 20:12:30 13 августа 2010, Пятница,
отправитель Gary Johnson:

>     exe "source " . yyy . "\aaa.vim"
Here you must replace yyy with fnameescape(yyy), see :h fnameescape().

Текст сообщения:

> 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

signature.asc (205 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: use the variable

livim
In reply to this post by Gary Johnson-4
Wonderful!
Thank yo so much!


On 8月14日, 上午12时12分, Gary Johnson <[hidden email]> wrote:

> 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