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

Duplicate line without losing unnamed register?

Expand Messages
  • Saad Malik
    Hi All, This is a ViM ninja question. What is the most efficient way of duplicating a line without overwriting the unnamed register? For example, imagine the
    Message 1 of 3 , Aug 2, 2014
    • 0 Attachment
      Hi All,
      This is a ViM ninja question. What is the most efficient way of duplicating a line without overwriting the unnamed register?

      For example, imagine the following two lines in a buffer:

      this_is_a_really_long_word
      <bean id="duplicate_this_line" class="..." scope="prototype" />

      What'd I'd like to do is yank the "long" word (yiw), and then duplicate the <bean line, and then replace the id of the duplicated line with the yanked word in unnamed register. This of course doesn't work, because the duplicate operation (yyp), overwrites both the unnamed register and the copy ("0) register.

      I'm a sloppy yanker, and never remember to use registers. But if I did, then of course yanking the long word into a register ("ayiw) would be the most efficient way.

      However, after the fact that I've already yanked the word into the unnamed register, the only somewhat lengthy solution I've found is to copy the unnamed register into a named register (:let @a=@"), and then proceed with duplicating the line and changing the id attribute (vi""ap).

      Anyone have a better solution?

      --
      --
      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.
    • Tim Chase
      ... I tend to use ... to copy the current line to the line below it without messing up my ... -tim -- -- You received this message from the vim_use maillist.
      Message 2 of 3 , Aug 2, 2014
      • 0 Attachment
        On 2014-08-02 10:28, Saad Malik wrote:
        > Hi All,
        > This is a ViM ninja question. What is the most efficient way of
        > duplicating a line without overwriting the unnamed register?

        I tend to use

        :t.

        to copy the current line to the line below it without messing up my
        scratch register. You can specify other destinations if you prefer:

        :t$ " copy this line to the end of the file
        :t0 " copy this line to the beginning of the file
        :t+3 " copy this line to 3 lines below
        :t/pattern/ " copy this line after the next line containing "pattern"
        :t/pattern/-3 " copy to 3 lines before the next match of "pattern"

        -tim


        --
        --
        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.
      • Saad Malik
        ... Now this is cool! Thanks. -- -- You received this message from the vim_use maillist. Do not top-post! Type your reply below the text you are replying to.
        Message 3 of 3 , Aug 2, 2014
        • 0 Attachment
          On Saturday, August 2, 2014 10:51:43 AM UTC-7, Tim Chase wrote:
          > On 2014-08-02 10:28, Saad Malik wrote:
          >
          > > Hi All,
          >
          > > This is a ViM ninja question. What is the most efficient way of
          >
          > > duplicating a line without overwriting the unnamed register?
          >
          > I tend to use
          > :t.
          >

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