Saturday, April 3, 2010

Re: vim scripting - using variables

On 03/04/10 19:31, dave73 wrote:
>
> I'm trying to integrate cscope with vim. The standard method to load the
> cscope.out file is simply:
>
> if filereadable("cscope.out")
> cs add cscope.out
> endif
>
> But this requires always starting vim from the directory with the cscope.out
> file. Yuk.
>
> So, I've written a function that scans upward until if find the cscope.out
> file, and stores that in a variable. For example s:csfile might end up
> "../../cscope.out"
>
> However,
>
> cs add s:csfile
>
> doesn't work! It is trying to actually open a file called "s:csfile". How
> do I make vim translate this variable into a literal so that "cs add" will
> work???
>
> Thanks.

If you know from which directory the cscope database was built, you
should add that as a second parameter in the "cscope add" command (or
else you _have_ to run all cscope commands in that directory: Yuk). For
example, I have this in my vimrc

let $VIMSRC = '/root/.build/vim/vim' . (version / 100) . (version %
100)
command Cscope -nargs=0 cs add $VIMSRC/src/cscope.out $VIMSRC/src


Then typing :Cscope at the command-line loads my cscope database for the
current Vim source.


See also http://vim.wikia.com/wiki/Cscope

telling how I build my cscope database, and the options and
abbreviations I use to smooth my cscope use.


Now back to your question: To include the _value_ of a Vim variable
(rather than its _name_) in an ex-command, see :help :execute. The
cscope example above bypasses the problem by means of an _environment_
variable (which, however, unlike your s: variable, is not script-local
but common to all of Vim and all its child processes).


Best regards,
Tony.
--
"Never be afraid to tell the world who you are."
-- Anonymous

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

To unsubscribe, reply using "remove me" as the subject.

No comments: