Loading ...
Sorry, an error occurred while loading the content.

Yanking text from function

Expand Messages
  • Thiago Padilha
    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
    Message 1 of 4 , Apr 4 11:35 AM
    • 0 Attachment
      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@....
      For more options, visit https://groups.google.com/groups/opt_out.
    • Kent
      how about at the end of your function: normal! gvy ... -- -- You received this message from the vim_use maillist. Do not top-post! Type your reply below the
      Message 2 of 4 , Apr 4 12:49 PM
      • 0 Attachment
        how about at the end of your function:

        normal! gvy




        On Thu, Apr 4, 2013 at 8:35 PM, Thiago Padilha <tpadilha84@...> 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@....
        > For more options, visit https://groups.google.com/groups/opt_out.
        >
        >

        --
        --
        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@....
        For more options, visit https://groups.google.com/groups/opt_out.
      • Salman Halim
        ... -- -- 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,
        Message 3 of 4 , Apr 4 12:56 PM
        • 0 Attachment



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

          normal! gvy




          On Thu, Apr 4, 2013 at 8:35 PM, Thiago Padilha <tpadilha84@...> 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@....
          > 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@....
          For more options, visit https://groups.google.com/groups/opt_out.
           
           
        • Thiago Padilha
          ... This worked perfectly, thanks. -- -- You received this message from the vim_use maillist. Do not top-post! Type your reply below the text you are
          Message 4 of 4 , Apr 4 2:18 PM
          • 0 Attachment
            >> 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).

            This worked perfectly, thanks.

            --
            --
            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@....
            For more options, visit https://groups.google.com/groups/opt_out.
          Your message has been successfully submitted and would be delivered to recipients shortly.