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

insert multitline from ruby script

Expand Messages
  • pierre
    Hi. I d like to insert a few lines of text with a ruby script in the current buffer. I know how to append one line to the current buffer, or to set the nth
    Message 1 of 5 , Mar 14, 2011
    • 0 Attachment
      Hi.
      I'd like to insert a few lines of text with a ruby script
      in the current buffer.

      I know how to append one line to the current buffer,
      or to set the nth line of the buffer. So in principle
      I can append a few lines with a loop. Am I missing
      something? is there a faster and more clever way?
      if I just append a multi-line string the linebreaks
      are converted into ^@ so I'm afraid the ruby support
      is still too early to get this easily, but one never
      knows, and you guys are so resourceful.

      Thanks
      Piero

      --
      You received this message from the "vim_mac" 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
    • Derek Wyatt
      Have a look in help for the expression register. This video should make it pretty clear, if you re not illuminated bt the help file:
      Message 2 of 5 , Mar 14, 2011
      • 0 Attachment
        Have a look in help for the expression register. This video should make it pretty clear, if you're not illuminated bt the help file:

        http://www.derekwyatt.org/vim/vim-tutorial-videos/vim-advanced-tutorial-videos/#expression-register

        Regs,
        Derek

        Entered using opposable digits


        From: pierre <pierredelun3@...>
        Sender: vim_mac@...
        Date: Mon, 14 Mar 2011 16:21:36 -0700 (PDT)
        To: <vim_mac@...>
        ReplyTo: vim_mac@...
        Subject: insert multitline from ruby script

        Hi.
        I'd like to insert a few lines of text with a ruby script
        in the current buffer.

        I know how to append one line to the current buffer,
        or to set the nth line of the buffer. So in principle
        I can append a few lines with a loop. Am I missing
        something? is there a faster and more clever way?
        if I just append a multi-line string the linebreaks
        are converted into ^@ so I'm afraid the ruby support
        is still too early to get this easily, but one never
        knows, and you guys are so resourceful.

        Thanks
        Piero

        --
        You received this message from the "vim_mac" 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 from the "vim_mac" 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
      • pierre
        It works indeed :) Thank you Piero -- You received this message from the vim_mac maillist. Do not top-post! Type your reply below the text you are replying
        Message 3 of 5 , Mar 14, 2011
        • 0 Attachment
          It works indeed :)
          Thank you
          Piero

          --
          You received this message from the "vim_mac" 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
        • pierre
          Ahem!... another difficulty The technique =system( ruby /path/to/file ) works nicely apart from a problem: I can no longer access things like VIM::Buffer
          Message 4 of 5 , Mar 15, 2011
          • 0 Attachment
            Ahem!... another difficulty

            The technique   
            <C-R>=system("ruby /path/to/file")
            works nicely apart from a problem: I can no longer
            access things like VIM::Buffer in my ruby script, while
            they work ok if I use
            :rubyf /path/to/file
            on the command line.

            So, what is the proper way to go?
            1) install the required vim-ruby packages on my system
            (but which are the good ones?)
            2) inside my script, require or load the appropriate
            definitions (but where are they? inside macvim?
            inside /usr/share? in some ruby Framework?)
            3) last option: ask the list and let them explain to me
            what I'm missing. I'm sure there is a trivial solution

            Thanks, 
            Piero

            --
            You received this message from the "vim_mac" 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
          • björn
            ... Instead of sytem(...) you can call any Vim function...in particular you can supply your own. For example: function! Test() return hi! endfunction You
            Message 5 of 5 , Mar 21, 2011
            • 0 Attachment
              On 15 March 2011 14:02, pierre wrote:
              > Ahem!... another difficulty
              > The technique
              > <C-R>=system("ruby /path/to/file")
              > works nicely apart from a problem: I can no longer
              > access things like VIM::Buffer in my ruby script, while
              > they work ok if I use
              > :rubyf /path/to/file
              > on the command line.

              Instead of sytem(...) you can call any Vim function...in particular
              you can supply your own. For example:

              function! Test()
              return "hi!"
              endfunction

              You can now <C-R>=Test() and "hi!" will be inserted into the buffer.
              If you need more help with this you should ask on the vim_use Google
              Group.

              Björn

              --
              You received this message from the "vim_mac" 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
            Your message has been successfully submitted and would be delivered to recipients shortly.