value of a variable within a expression

10 views
Skip to first unread message

Jonas Geiregat

unread,
Feb 1, 2011, 8:04:51 PM2/1/11
to vim...@googlegroups.com
Hello,

You have to excuse me if this is a silly question. But as you might have guessed I'm new to vim.

I've defined a variable s:nfile and want to use it in the following expression.

!stylus < '%:p' > s:nfile

This doesn't work and really runs !stylus < whatever_is_the_current_file > s:nfile.

I've tried everything from echo s:nfile to let s:nfile within the expression.

Thanks in advance,

Jonas Geiregat.

ZyX

unread,
Feb 1, 2011, 11:50:38 PM2/1/11
to vim...@googlegroups.com
Reply to message «value of a variable within a expression»,
sent 04:04:51 02 February 2011, Wednesday
by Jonas Geiregat:

> !stylus < '%:p' > s:nfile
>
> This doesn't work and really runs !stylus < whatever_is_the_current_file >
> s:nfile.
>
> I've tried everything from echo s:nfile to let s:nfile within the
> expression.

You should use :execute in such cases:
execute '!stylus < '.shellescape(expand('%:p'), 1).
\' > '.shellescape(s:nfile, 1)
Note that using «'%:p'» is not sufficient to escape filename: try it when
filename contents odd number of a single quotes.

Original message:

signature.asc

Christian Brabandt

unread,
Feb 2, 2011, 4:42:11 PM2/2/11
to vim...@googlegroups.com
Hi Jonas!

This is becoming a faq and there is also an entry� on the faq, that
covers this question:
http://vimhelp.appspot.com/vim_faq.txt.html#faq-25.14

�)Well, the question only barely mentions your specific problem, but the
general problem on how to evaluate a vim variable with an :ex command is
still covered. Anybody wants to improve the text?

regards,
Christian

Reply all
Reply to author
Forward
0 new messages