Tuesday, January 28, 2014

Re: map with empty yank

Hi Carlos!

On Di, 28 Jan 2014, Carlos Pita wrote:

> I would like to yank the inner contents of <...> or (...) expressions
> in a mapping. In normal mode I can try with the two-yank sequence
> yi<yi(. One of the yanks will be empty and the other will match the
> desired contents. The net effect is to match the contents no matter
> they were inside () or <>. Now if I put that in a map it seems to
> abort when the first yank fails, so it only matches the contents for
> <...> expressions (because yi< is the first probed yank). If I put
> :normal yi<<CR>:normal yi( instead, the mapping works the same than
> when I manually type it in normal mode. The E flag is not included in
> my cpoptions.
>
> Could someone clarify this behavior, please?

That is explained (although only briefly) at :h map-error

I am not sure, there is an easy way to achieve what you want. I think,
something like this could work:

fu! MapAngle()
if searchpairpos('<', '', '>', 'bn') ==# [0,0]
return "i("
else
return "i<"
endif
endfu

omap <expr> i_ MapAngle()


Best,
Christian
--
"But Huey, you PROMISED!"
"Tell 'em I lied."

--
--
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.
For more options, visit https://groups.google.com/groups/opt_out.

No comments: