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

Script to send selected text from Vim to R in Ubuntu

Expand Messages
  • Josef Montag
    Hi all, I have started using Ubuntu and try to figure out ways and tools for a simple script. I use Vim to write code for R and need a script that takes a
    Message 1 of 6 , Feb 5, 2013
    • 0 Attachment
      Hi all,

      I have started using Ubuntu and try to figure out ways and tools for a simple script. I use Vim to write code for R and need a script that takes a selection in Vim and sends it to R and have this script attached to a key combination. I'm not sure whether this could all be done in Vimscript or I should look elsewhere.

      Thanks for any tips!

      Josef

      --
      --
      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.
    • Gary Johnson
      ... To send a visually-selected region to the standard input of an external program such as R, type the following ... See ... You can map a key combination to
      Message 2 of 6 , Feb 5, 2013
      • 0 Attachment
        On 2013-02-05, Josef Montag wrote:
        > Hi all,
        >
        > I have started using Ubuntu and try to figure out ways and tools
        > for a simple script. I use Vim to write code for R and need a
        > script that takes a selection in Vim and sends it to R and have
        > this script attached to a key combination. I'm not sure whether
        > this could all be done in Vimscript or I should look elsewhere.

        To send a visually-selected region to the standard input of an
        external program such as R, type the following

        :w !R

        which will appear on the command line as:

        :'<,'>w !R

        See

        :help visual.txt
        :help :w_c
        :help 10.9

        You can map a key combination to any sequence of Vim commands
        including this one, for example,

        :vmap <F3> :w !R<CR>

        See

        :help 05.3
        :help 40.1
        :help map.txt

        HTH,
        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@....
        For more options, visit https://groups.google.com/groups/opt_out.
      • John Beckett
        ... An example using Python is here: http://vim.wikia.com/wiki/Use_filter_commands_to_process_text ... John -- -- You received this message from the vim_use
        Message 3 of 6 , Feb 5, 2013
        • 0 Attachment
          Josef Montag wrote:
          > I have started using Ubuntu and try to figure out ways and
          > tools for a simple script. I use Vim to write code for R and
          > need a script that takes a selection in Vim and sends it to R
          > and have this script attached to a key combination. I'm not
          > sure whether this could all be done in Vimscript or I should
          > look elsewhere.

          An example using Python is here:
          http://vim.wikia.com/wiki/Use_filter_commands_to_process_text

          To make a mapping of the command in the example, you could do:

          :vnoremap <F8> !python sortwords.py<CR>

          John

          --
          --
          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.
        • lith
          ... You should probably run R via screen/tmux and then use a vim plugin for screen/tmux to send the code to R. You could either use a generic plugin or, e.g.,
          Message 4 of 6 , Feb 5, 2013
          • 0 Attachment
            > a script that takes a selection in Vim and sends it to R

            You should probably run R via screen/tmux and then use a vim plugin for screen/tmux to send the code to R. You could either use a generic plugin or, e.g., rcom[1] (which can use screen.vim or its own functions) for that purpose.

            Since your question is specifically about R, you might also want to check the vim-R-plugin[2], which provides a more complete, more sophisticated, but also more complex solution for your problem.

            HTH


            [1] https://github.com/tomtom/rcom_vim
            [2] http://www.vim.org/scripts/script.php?script_id=2628

            --
            --
            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.
          • tooth pik
            ... the simplest way to filter text through an external filter is to ... where {scriptname} is written to receive its input on sysin -- all of [range] in your
            Message 5 of 6 , Feb 6, 2013
            • 0 Attachment
              On Tue, Feb 05, 2013 at 08:45:10AM -0800, Josef Montag wrote:
              > Hi all,

              > I have started using Ubuntu and try to figure out ways and tools for
              > a simple script. I use Vim to write code for R and need a script
              > that takes a selection in Vim and sends it to R and have this script
              > attached to a key combination. I'm not sure whether this could all
              > be done in Vimscript or I should look elsewhere.

              the simplest way to filter text through an external filter is to
              execute:

              :[range]!{scriptname}

              where {scriptname} is written to receive its input on sysin -- all of
              [range] in your text will be replaced with the output from
              {scriptname}

              this gives you the flexibility to write {scriptname} in whatever
              language pleases you, as fancy or as simple as need requires

              sc

              --
              --
              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.
            • Josef Montag
              ... Thanks a lot to you all guys. This got me started. Enjoy your weekends. J. -- -- You received this message from the vim_use maillist. Do not top-post!
              Message 6 of 6 , Feb 8, 2013
              • 0 Attachment
                On Thursday, February 7, 2013 12:54:26 AM UTC+1, toothpik wrote:
                > On Tue, Feb 05, 2013 at 08:45:10AM -0800, Josef Montag wrote:
                >
                > > Hi all,
                >
                >
                >
                > > I have started using Ubuntu and try to figure out ways and tools for
                >
                > > a simple script. I use Vim to write code for R and need a script
                >
                > > that takes a selection in Vim and sends it to R and have this script
                >
                > > attached to a key combination. I'm not sure whether this could all
                >
                > > be done in Vimscript or I should look elsewhere.
                >
                >
                >
                > the simplest way to filter text through an external filter is to
                >
                > execute:
                >
                >
                >
                > :[range]!{scriptname}
                >
                >
                >
                > where {scriptname} is written to receive its input on sysin -- all of
                >
                > [range] in your text will be replaced with the output from
                >
                > {scriptname}
                >
                >
                >
                > this gives you the flexibility to write {scriptname} in whatever
                >
                > language pleases you, as fancy or as simple as need requires
                >
                >
                >
                > sc

                Thanks a lot to you all guys. This got me started. Enjoy your weekends. J.

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