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

Re: bufdo broken in 7.2.325?

Expand Messages
  • Tim Chase
    ... Using bufdo requires leaving ( abandoning ) the buffer. If you ve made changes, you either need to write them as part of ... or you have to ... to allow
    Message 1 of 7 , Jan 1, 2010
    • 0 Attachment
      > I was in the process of updating the copyright date for a whole bunch
      > of my source files that I had open in buffers in vim. I tried:
      >
      > :bufdo %s/2009/2010/ge
      >
      > All it did was update the first buffer.
      >
      > Did I do something wrong with bufdo, or is it broken?

      Using bufdo requires leaving ("abandoning") the buffer. If
      you've made changes, you either need to write them as part of
      your command:

      :bufdo %s/foo/bar/ge | update

      or you have to

      :set hidden

      to allow vim to leave the modified buffer while preserving the
      changes. I didn't see mention of either in your email, so my
      guess would be that either one will solve the issue. I prefer
      the 'hidden' method so I can go back and review my changes before
      issuing a

      :wall

      to write them, just in case I did something bone-headed.

      You might also be able to use 'autowrite' or 'autowriteall', but
      I prefer to have greater control over my writes, so I dislike
      those options.

      :help abandon
      :help 'hidden'
      :help bufdo

      for more info on the peculiarities.

      -tim


      --
      You received this message from the "vim_use" maillist.
      For more information, visit http://www.vim.org/maillist.php
    • Tony Mechelynck
      ... Unless you have hidden autowrite or autowriteall set, your first command will refuse to |abandon| the modified buffer (see :help ... -- and BTW,
      Message 2 of 7 , Jan 1, 2010
      • 0 Attachment
        On 02/01/10 01:35, Chris Sutcliffe wrote:
        > Hi All,
        >
        > I was in the process of updating the copyright date for a whole bunch
        > of my source files that I had open in buffers in vim. I tried:
        >
        > :bufdo %s/2009/2010/ge
        >
        > All it did was update the first buffer. I executed:
        >
        > :tab sball
        >
        > to get all the buffers into tabs and executed:
        >
        > :tabdo %s/2009/2010/ge
        >
        > and it worked just fine. Did I do something wrong with bufdo, or is it broken?
        >
        > I'm running vim 7.2.325 in Cygwin on Windows XP Pro.
        >
        > Cheers!
        >
        > Chris
        >

        Unless you have 'hidden' 'autowrite' or 'autowriteall' set, your first
        command will refuse to |abandon| the modified buffer (see ":help
        abandon"). You should have done:

        :bufdo %s/2009/2010/ge |update

        -- and BTW, beware that the above will also change 120090 to 120100.

        With every buffer in a different tab (or in a different window), :tabdo
        or :windo doesn't have the same problem, which explains why your second
        command worked.


        Best regards,
        Tony.
        --
        Xerox never comes up with anything original.

        --
        You received this message from the "vim_use" maillist.
        For more information, visit http://www.vim.org/maillist.php
      • Chris Sutcliffe
        ... I tried :bufdo! %s/2009/2010/ge and it behaved as expected (hiding the buffers that were modified). ... Good point. How do I search for white space
        Message 3 of 7 , Jan 2, 2010
        • 0 Attachment
          > Unless you have 'hidden' 'autowrite' or 'autowriteall' set, your first
          > command will refuse to |abandon| the modified buffer (see ":help abandon").
          > You should have done:
          >
          >        :bufdo %s/2009/2010/ge |update

          I tried ':bufdo! %s/2009/2010/ge' and it behaved as expected (hiding
          the buffers that were modified).

          > -- and BTW, beware that the above will also change 120090 to 120100.

          Good point. How do I search for white space before and after the 2009
          and replace it with 2010 saving the white space?

          Thank you all for your replies.

          Chris

          --
          Chris Sutcliffe
          http://emergedesktop.org

          --
          You received this message from the "vim_use" maillist.
          For more information, visit http://www.vim.org/maillist.php
        • Christian Brabandt
          Hi Chris! ... regards, Christian -- hundred-and-one symptoms of being an internet addict: 45. You buy a Captain Kirk chair with a built-in keyboard and mouse.
          Message 4 of 7 , Jan 2, 2010
          • 0 Attachment
            Hi Chris!

            On Sa, 02 Jan 2010, Chris Sutcliffe wrote:

            > Good point. How do I search for white space before and after the 2009
            > and replace it with 2010 saving the white space?
            :%s/\<2009\>/2010/g

            regards,
            Christian
            --
            hundred-and-one symptoms of being an internet addict:
            45. You buy a Captain Kirk chair with a built-in keyboard and mouse.

            --
            You received this message from the "vim_use" maillist.
            For more information, visit http://www.vim.org/maillist.php
          • Tony Mechelynck
            ... that s if hidden is set; but maybe it wasn t set before? I don t use hidden myself because I don t like having unsaved files out of sight (but then, I
            Message 5 of 7 , Jan 2, 2010
            • 0 Attachment
              On 02/01/10 13:59, Chris Sutcliffe wrote:
              >> Unless you have 'hidden' 'autowrite' or 'autowriteall' set, your first
              >> command will refuse to |abandon| the modified buffer (see ":help abandon").
              >> You should have done:
              >>
              >> :bufdo %s/2009/2010/ge |update
              >
              > I tried ':bufdo! %s/2009/2010/ge' and it behaved as expected (hiding
              > the buffers that were modified).

              that's if 'hidden' is set; but maybe it wasn't set before? I don't use
              'hidden' myself because I don't like having unsaved files out of sight
              (but then, I use 'autowriteall' so it would have worked for me, saving
              all files except maybe the last one which would remain open).

              >
              >> -- and BTW, beware that the above will also change 120090 to 120100.
              >
              > Good point. How do I search for white space before and after the 2009
              > and replace it with 2010 saving the white space?

              You could search for word boundaries: %s/\<2009\>/2010/ge where \< means
              "start of word" and \> means "end of word" (both are zero-length matches).

              >
              > Thank you all for your replies.
              >
              > Chris
              >

              Best regards,
              Tony.
              --
              "Why isn't there a special name for the tops of your feet?"
              -- Lily Tomlin

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