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

How to sent a Visual Selection to an Interactive REPL?

Expand Messages
  • Nishant Varma
    Usecase: I write/copy paste lot of snippets that needs to be evaluated in REPL . For example the second answer to this questions
    Message 1 of 5 , Jun 17, 2014
    • 0 Attachment
      Usecase:

      I write/copy paste lot of snippets that needs to be evaluated in REPL . For example the second answer to this questions http://stackoverflow.com/questions/100003/what-is-a-metaclass-in-python .

      Problem:
      I can do this by copy paste or loading the entire file in REPL but its an overhead sometimes .

      Solution ?
      What is the simplest way to pass a visual region to a repl in an interactive manner ?

      I came across http://stackoverflow.com/questions/7906858/vim-run-selected-code-in-a-persistent-repl-environment.

      However what I need is simple way to start a REPL from a VIM Visual selection with stdin as the Visual Input . This sounds way to trivial to be NOT POSSIBLE . How can the visual buffer can be piped into python with no filtering back or handling the output .

      For example

      Some Other Code

      Class Foo():
      pass

      Some Other Code

      I need to be able to select only Class Foo() and enter the REPL with Foo visible in the namespace of the REPL . I have seen many variants like filter back the output etc . But this is more for learning Python Snippets etc and I prefer writing in VIM as opposed to REPL .

      PS This Question Is Actually for Python:

      I figured that this will work to get a persistent python REPL with stdin in bash :

      python -i <(echo "class Foo(object):pass").
      Now I can python python -i <(echo "{HERE}")
      I can do a <C-R>* there to get my input but it all seems hack .

      --
      --
      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/d/optout.
    • Nishant Varma
      I could do this : vnoremap : !python -i But it won t handle # etc . For example : x = 1, 2, 3 # what kind of sequence
      Message 2 of 5 , Jun 17, 2014
      • 0 Attachment
        I could do this :

        vnoremap <F6> :<C-U>!python -i <(echo '''<C-R><C-R>*''') <CR>

        But it won't handle # etc .

        For example :
        x = 1, 2, 3 # what kind of sequence is x?
        # Becomes the filename !

        On Tuesday, 17 June 2014 14:55:50 UTC+5:30, Nishant Varma wrote:
        > Usecase:
        >
        > I write/copy paste lot of snippets that needs to be evaluated in REPL . For example the second answer to this questions http://stackoverflow.com/questions/100003/what-is-a-metaclass-in-python .
        >
        > Problem:
        > I can do this by copy paste or loading the entire file in REPL but its an overhead sometimes .
        >
        > Solution ?
        > What is the simplest way to pass a visual region to a repl in an interactive manner ?
        >
        > I came across http://stackoverflow.com/questions/7906858/vim-run-selected-code-in-a-persistent-repl-environment.
        >
        > However what I need is simple way to start a REPL from a VIM Visual selection with stdin as the Visual Input . This sounds way to trivial to be NOT POSSIBLE . How can the visual buffer can be piped into python with no filtering back or handling the output .
        >
        > For example
        >
        > Some Other Code
        >
        > Class Foo():
        > pass
        >
        > Some Other Code
        >
        > I need to be able to select only Class Foo() and enter the REPL with Foo visible in the namespace of the REPL . I have seen many variants like filter back the output etc . But this is more for learning Python Snippets etc and I prefer writing in VIM as opposed to REPL .
        >
        > PS This Question Is Actually for Python:
        >
        > I figured that this will work to get a persistent python REPL with stdin in bash :
        >
        > python -i <(echo "class Foo(object):pass").
        > Now I can python python -i <(echo "{HERE}")
        > I can do a <C-R>* there to get my input but it all seems hack .

        --
        --
        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/d/optout.
      • LCD 47
        ... [...] Not sure this would qualify as simplest , but IPython[0] + vim-ipython[1] can do that for Python. The Vim plugin used to have a number of issues,
        Message 3 of 5 , Jun 17, 2014
        • 0 Attachment
          On 17 June 2014, Nishant Varma <nishant.varma@...> wrote:
          > Usecase:
          >
          > I write/copy paste lot of snippets that needs to be evaluated
          > in REPL . For example the second answer to this questions
          > http://stackoverflow.com/questions/100003/what-is-a-metaclass-in-python .
          >
          > Problem:
          > I can do this by copy paste or loading the entire file in REPL but its
          > an overhead sometimes .
          >
          > Solution ?
          > What is the simplest way to pass a visual region to a repl in an
          > interactive manner ?
          [...]

          Not sure this would qualify as "simplest", but IPython[0] +
          vim-ipython[1] can do that for Python. The Vim plugin used to have a
          number of issues, but maybe they have been fixed in the mean time.

          /lcd

          [0]: http://ipython.org/
          [1]: https://github.com/ivanov/vim-ipython

          --
          --
          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/d/optout.
        • Nishant Varma
          ... Thanks LCD . Another Trivial solution is : vnoremap :w! /tmp/tmp.py !python -i /tmp/tmp.py nnoremap :w! /tmp/tmp.py !python -i
          Message 4 of 5 , Jun 17, 2014
          • 0 Attachment
            On Tuesday, 17 June 2014 17:37:47 UTC+5:30, LCD 47 wrote:
            > On 17 June 2014, Nishant Varma <nishant.varma@...> wrote:
            >
            > > Usecase:
            >
            > >
            >
            > > I write/copy paste lot of snippets that needs to be evaluated
            >
            > > in REPL . For example the second answer to this questions
            >
            > > http://stackoverflow.com/questions/100003/what-is-a-metaclass-in-python .
            >
            > >
            >
            > > Problem:
            >
            > > I can do this by copy paste or loading the entire file in REPL but its
            >
            > > an overhead sometimes .
            >
            > >
            >
            > > Solution ?
            >
            > > What is the simplest way to pass a visual region to a repl in an
            >
            > > interactive manner ?
            >
            > [...]
            >
            >
            >
            > Not sure this would qualify as "simplest", but IPython[0] +
            >
            > vim-ipython[1] can do that for Python. The Vim plugin used to have a
            >
            > number of issues, but maybe they have been fixed in the mean time.
            >
            >
            >
            > /lcd
            >
            >
            >
            > [0]: http://ipython.org/
            >
            > [1]: https://github.com/ivanov/vim-ipython

            Thanks LCD .

            Another Trivial solution is :

            vnoremap <F6> :w! /tmp/tmp.py <bar> !python -i /tmp/tmp.py<CR>
            nnoremap <F6> :w! /tmp/tmp.py <bar> !python -i /tmp/tmp.py<CR>

            But its hard coded to Python .

            I wanted to make it generic somehow .

            --
            --
            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/d/optout.
          • Nishant Varma
            ... So presently the best I have is : nnoremap :w! /tmp/tmp.py !python -i /tmp/tmp.py vnoremap :w! /tmp/tmp.py !python -i
            Message 5 of 5 , Jun 17, 2014
            • 0 Attachment
              On Tuesday, 17 June 2014 17:37:47 UTC+5:30, LCD 47 wrote:
              > On 17 June 2014, Nishant Varma <nishant.varma@...> wrote:
              >
              > > Usecase:
              >
              > >
              >
              > > I write/copy paste lot of snippets that needs to be evaluated
              >
              > > in REPL . For example the second answer to this questions
              >
              > > http://stackoverflow.com/questions/100003/what-is-a-metaclass-in-python .
              >
              > >
              >
              > > Problem:
              >
              > > I can do this by copy paste or loading the entire file in REPL but its
              >
              > > an overhead sometimes .
              >
              > >
              >
              > > Solution ?
              >
              > > What is the simplest way to pass a visual region to a repl in an
              >
              > > interactive manner ?
              >
              > [...]
              >
              >
              >
              > Not sure this would qualify as "simplest", but IPython[0] +
              >
              > vim-ipython[1] can do that for Python. The Vim plugin used to have a
              >
              > number of issues, but maybe they have been fixed in the mean time.
              >
              >
              >
              > /lcd
              >
              >
              >
              > [0]: http://ipython.org/
              >
              > [1]: https://github.com/ivanov/vim-ipython

              So presently the best I have is :

              nnoremap <F6> :w! /tmp/tmp.py <bar> !python -i /tmp/tmp.py<CR>
              vnoremap <F6> :w! /tmp/tmp.py <bar> !python -i /tmp/tmp.py<CR>

              And another recommendation is https://github.com/zweifisch/pipe2eval which was recommended to me .

              --
              --
              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/d/optout.
            Your message has been successfully submitted and would be delivered to recipients shortly.