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

Re: copy and replace with a slight modification a line several times

Expand Messages
  • Ben Fritz
    ... Oops, I guess I wanted append(). I thought I used setline() in TOhtml like this, but I only do it this way when the new buffer is empty. For adding text
    Message 1 of 7 , Dec 11, 2012
    • 0 Attachment
      On Tuesday, December 11, 2012 6:55:30 PM UTC-6, JohnBeckett wrote:
      > Ben Fritz wrote:
      >
      > > ...
      >
      > > call setline(".",[line,repl1,repl2,repl3])
      >
      >
      >
      > There is a problem with that because four lines will be inserted
      >
      > into the buffer, and those lines will OVERWRITE existing lines.
      >
      > That's why my script used 'setline()' to replace the first line,
      >
      > and 'put' to insert the extra lines.
      >

      Oops, I guess I wanted append(). I thought I used setline() in TOhtml like this, but I only do it this way when the new buffer is empty. For adding text TOhtml uses append().

      --
      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
    • A Loumiotis
      ... Many thanks John and Ben for your help. I m not sure though how to use nr2char() for the second change. However, I slightly modified John s convert()
      Message 2 of 7 , Dec 14, 2012
      • 0 Attachment
        On Wed, Dec 12, 2012 at 3:27 AM, Ben Fritz <fritzophrenic@...> wrote:
        On Tuesday, December 11, 2012 6:55:30 PM UTC-6, JohnBeckett wrote:
        > Ben Fritz wrote:
        >
        > > ...
        >
        > > call setline(".",[line,repl1,repl2,repl3])
        >
        >
        >
        > There is a problem with that because four lines will be inserted
        >
        > into the buffer, and those lines will OVERWRITE existing lines.
        >
        > That's why my script used 'setline()' to replace the first line,
        >
        > and 'put' to insert the extra lines.
        >

        Oops, I guess I wanted append(). I thought I used setline() in TOhtml like this, but I only do it this way when the new buffer is empty. For adding text TOhtml uses append().

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

        Many thanks John and Ben for your help.  I'm not sure though how to use nr2char() for the second change.  However, I slightly modified John's convert() function and got the required result:

        function! Conva_d(linenr)
          let line = getline(a:linenr)
          let result = []
          for i in ["a","b","c","d"]
            call add(result, substitute(line, 'x\(\w\)\@!','_' . i, 'g'))
          endfor
          call setline(a:linenr, result[0])
          execute a:linenr . 'put =result[1:]'
        endfunction

        --
        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
      • John Beckett
        ... From something Ben mentioned, the line: execute a:linenr . put =result[1:] is more cleanly written as: call append(a:linenr, result[1:]) John -- You
        Message 3 of 7 , Dec 14, 2012
        • 0 Attachment
          A Loumiotis wrote:
          > function! Conva_d(linenr)
          > let line = getline(a:linenr)
          > let result = []
          > for i in ["a","b","c","d"]
          > call add(result, substitute(line, 'x\(\w\)\@!','_' . i, 'g'))
          > endfor
          > call setline(a:linenr, result[0])
          > execute a:linenr . 'put =result[1:]'
          > endfunction

          From something Ben mentioned, the line:
          execute a:linenr . 'put =result[1:]'

          is more cleanly written as:
          call append(a:linenr, result[1:])

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