Friday, February 14, 2020

Re: nested expr in a mapping

On 2020-02-14, M Kelly wrote:
> Hi,
>
> ok, thank you.
> I always thought there had to be quotes around each block, as in () ? 'foo' :
> 'bar'
> So I was trying \' and \\' and \" and \\" and extra quotes for each additional
> nested block to no success.
> I will remove all quotes and see if I can get it to work.

The quotes are necessary if the expression evaluates to a string and
each of the alternatives is a literal string.

Here are some simple examples.

:let x = 1
:echo x == 1 ? 73 : 88
73

:echo x == 0 ? "hello" : "goodbye"
goodbye

In the first example, the expression evaluates to a number, while in
the second example the expression evaluates to a string.

Here's an example of nesting.

:let x = 2
:echo x == 1 ? "one" : x == 2 ? "two" : "something else"
two

I deliberately didn't use any parentheses to show that they're often
not necessary, although they can make expressions more clear.

If you can't get it to work, post what you've tried here and we'll
figure it out.

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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/20200215071733.GD9366%40phoenix.

No comments: