Thursday, April 28, 2022

Re: syntax for "map key test?'cmd1':'cmd2'|:cmd3|:cmd4"

Got it to work.
Thank you all!

On Wednesday, April 27, 2022 at 1:39:23 AM UTC-7 jottkaerr@googlemail.com wrote:
Hi,

Christian Brabandt schrieb am 27.04.2022 um 10:02:
>
> On Di, 26 Apr 2022, dado wrote:
>
>> I have the following (pseudo code) mapping working:
>> nmap <expr> key some-expr ?
>> \ 'cmd1<Bar>:cmd3<CR><Bar>:cmd4<CR>' :
>> \ 'cmd2<Bar>:cmd3<CR><Bar>:cmd4<CR>'
>>
>> As you can see the conditional selects between cmd1 and cmd2, but both
>> execute cmd3 and cmd4.
>> I'd like to move cmd3 and cmd4 outside of the conditional as in
>> nmap <expr> key some-expr?'cmd1':'cmd2'<Bar>:cmd3<CR><Bar>:cmd4<CR>
>> The problem is I get cmd1 or cmd2 to execute, but never cmd3 or cmd4.
>> I know I could move this to a function but I'd like to understand the
>> syntax.
>
> Try something like the following:
> nmap <expr> (key some-expr ? 'cmd1<Bar>' : 'cmd2<Bar>') .. ':cmd3<CR><Bar>:cmd4<CR>'
>
> Note sure about all the `<Bar>`s and `<CR>`s :)

:nmap <expr> <F8> ( &list ? ':echomsg 1<Bar>' : ':echomsg 2<Bar>' ) .. 'echomsg 3<Bar>echomsg 4<CR>'

works. If 'list' is set, pressing <F8> will output

1
3
4

If 'list' is not set, pressing <F8> will output

2
3
4

Note that there is no need for a colon after <Bar> and no need for <CR> before <Bar>.

Regards,

--
~
~
~
:wq

--
--
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/acb1f1de-9966-4f2d-9aa4-47ab59db002bn%40googlegroups.com.

No comments: