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

Register contents within pattern?

Expand Messages
  • NickC
    I want to use a register s contents as the pattern for a substitute. I can t find registers mentioned in the help for :sub or pattern. Is there a way I can
    Message 1 of 3 , Jan 1, 2010
    • 0 Attachment
      I want to use a register's contents as the pattern for a substitute. I
      can't find registers mentioned in the help for :sub or pattern. Is there
      a way I can do it?

      I'm trying to clean up some files that have been corrupted by being
      transferred between several hosts with different encodings and a buggy
      editor in the middle. It has become scattered with patterns of odd
      strings such as "甕" throughout. I figure it's easiest just to visual-yank
      the string to a register and use the register's contents as the pattern to
      substitute to a string of blanks.

      Thanks,
      --
      NickC

      --
      You received this message from the "vim_use" maillist.
      For more information, visit http://www.vim.org/maillist.php
    • Tim Chase
      ... From your description, yes. As you type the substitute command, you want to use control+R followed by the register into which you yanked it, such as ...
      Message 2 of 3 , Jan 1, 2010
      • 0 Attachment
        NickC wrote:
        > I want to use a register's contents as the pattern for a substitute. I
        > can't find registers mentioned in the help for :sub or pattern. Is there
        > a way I can do it?

        From your description, yes. As you type the substitute command,
        you want to use control+R followed by the register into which you
        yanked it, such as

        :%s/<c-r>"

        to insert the scratch register in the command. It works with
        named registers, so if you yank to register "z", you can use

        :%s/<c-r>z

        to pull its contents into the substitute. It works for any
        command line, not just :substitute commands, so you can pull down
        filenames, and other such things.

        :help c_CTRL-R

        for more info. The section following that in the help also has
        suggestions for pulling in other information (such as the word
        under the cursor, or the filename under the cursor).

        -tim


        --
        You received this message from the "vim_use" maillist.
        For more information, visit http://www.vim.org/maillist.php
      • NickC
        ... Thanks Tim, that s just the thing. -- NickC -- You received this message from the vim_use maillist. For more information, visit
        Message 3 of 3 , Jan 1, 2010
        • 0 Attachment
          On Fri, 01 Jan 2010 22:12:23 -0600, Tim Chase wrote:

          > :help c_CTRL-R
          >

          Thanks Tim, that's just the thing.


          --
          NickC

          --
          You received this message from the "vim_use" maillist.
          For more information, visit http://www.vim.org/maillist.php
        Your message has been successfully submitted and would be delivered to recipients shortly.