Thursday, April 4, 2013

Re: Yanking text from function




On Thu, Apr 4, 2013 at 3:49 PM, Kent <kent.yuan@gmail.com> wrote:
how about at the end of your function:

normal! gvy




On Thu, Apr 4, 2013 at 8:35 PM, Thiago Padilha <tpadilha84@gmail.com> wrote:
> Hi
>
> I would like to execute a certain function whenever I yank some text
> in visual mode and the best way I found to do this was to remap 'y':
>
> vnoremap <silent> y :call Hook()<cr>
>
> The problem is that this function replaces the default yank action so
> I need I way to manually yank from inside the function. Whats the best
> way to achieve this?
>
> --
> --
> 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.

 
You could just call "y" at the beginning of the mapping:

vnoremap <silent> y y:call Hook()<cr>

This has the added advantage of making the yanked text available in the Hook function in case you need to do something with it.

You can do this because, first, you said "noremap" so the second "y" wouldn't trigger the mapping and would just do a yank and, secondly, Vim lets you start a mapped sequence with the keys that actually launched the mapping and falls back to their default behaviour automatically to avoid recursive mappings (so you could do this even if you hadn't specified a noremap).

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