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

Vim trick to make all the same numbers to replace by the numbera in ascending order ?

Expand Messages
  • Arup Rakshit
    Hi Suppose, I have below data :   describe .employee_learning do     let(:user1) { FactoryGirl.create(:user, gender: f ) }     let(:user1) {
    Message 1 of 7 , Jul 2, 2014
    • 0 Attachment
      Hi Suppose,

      I have below data :

        describe ".employee_learning" do
          let(:user1) { FactoryGirl.create(:user, gender: 'f') }
          let(:user1) { FactoryGirl.create(:user, gender: 'f') }
          let(:user1) { FactoryGirl.create(:user, gender: 'f') }
          let(:user1) { FactoryGirl.create(:user, gender: 'f') }
          let(:user1) { FactoryGirl.create(:user, gender: 'f') }
          let(:user1) { FactoryGirl.create(:user, gender: 'f') }
          let(:user1) { FactoryGirl.create(:user, gender: 'f') }
          let(:user1) { FactoryGirl.create(:user, gender: 'f') }
        end

      Only first line I wrote.. then I did Shift + v, then yanked and then 7p. These many action created the above all similar lines. Now I am looking for a trick, so that I can make all user1(s), in one shot like user1-user7. Hope I am able tell you people about my expectation :-) Is this really possible ? or manually *r* command is the only trick to replace each 1 to 2,3,4 increasing order ?
       
      Regards,
      Arup Rakshit

      --
      --
      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.
    • David Fishburn
      On Wed, Jul 2, 2014 at 8:31 AM, Arup Rakshit ... There are many ways you can do this. function! Increment() let g:S=g:S+1 return
      Message 2 of 7 , Jul 2, 2014
      • 0 Attachment

        On Wed, Jul 2, 2014 at 8:31 AM, Arup Rakshit <aruprakshit@...> wrote:
        Hi Suppose,

        I have below data :

          describe ".employee_learning" do
            let(:user1) { FactoryGirl.create(:user, gender: 'f') }
            let(:user1) { FactoryGirl.create(:user, gender: 'f') }
            let(:user1) { FactoryGirl.create(:user, gender: 'f') }
            let(:user1) { FactoryGirl.create(:user, gender: 'f') }
            let(:user1) { FactoryGirl.create(:user, gender: 'f') }
            let(:user1) { FactoryGirl.create(:user, gender: 'f') }
            let(:user1) { FactoryGirl.create(:user, gender: 'f') }
            let(:user1) { FactoryGirl.create(:user, gender: 'f') }
          end

        Only first line I wrote.. then I did Shift + v, then yanked and then 7p. These many action created the above all similar lines. Now I am looking for a trick, so that I can make all user1(s), in one shot like user1-user7. Hope I am able tell you people about my expectation :-) Is this really possible ? or manually *r* command is the only trick to replace each 1 to 2,3,4 increasing order ?
         

        There are many ways you can do this.

        function! Increment()
        let g:S=g:S+1
        return g:S
        endfunction

        " For example, if you had a file with text like this: "(8 hours)"
        " and you want to sum up the number of hours you can do the following:

        :let g:S=0 "In global variable S we later find the result

        " Then perform a substitute command:
        " :%s/(user\zs1)/\=Increment(submatch(0))/g

        The above is untested.

        The way I usually do this is just with some of the very useful plugins around though.

        I use this one mainly:
        " VisInc - Visually Increment numbers/dates/days

        Visually select the 1 for as many lines as you want (using CTRL-V) and hit
        :I

        Which is far easier than the above.

        HTH,
        David

        --
        --
        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.
      • Stefan Klein
        Hi, you could use a macro the create the multiple lines at first place, start with let(:user1) { FactoryGirl.create(:user, gender: f ) } press qa to record
        Message 3 of 7 , Jul 2, 2014
        • 0 Attachment
          Hi,

          you could use a macro the create the multiple lines at first place, start with

              let(:user1) { FactoryGirl.create(:user, gender: 'f') }

          press "qa" to record macro "a"
          yypCtrl+aq; yank line, paste line, increment first number, stop recording.
          Now you just call the macro 5 times: 5@a

          Hope you get what you are looking for.

          regards,
          Stefan




          2014-07-02 14:31 GMT+02:00 Arup Rakshit <aruprakshit@...>:
          Hi Suppose,

          I have below data :

            describe ".employee_learning" do
              let(:user1) { FactoryGirl.create(:user, gender: 'f') }
              let(:user1) { FactoryGirl.create(:user, gender: 'f') }
              let(:user1) { FactoryGirl.create(:user, gender: 'f') }
              let(:user1) { FactoryGirl.create(:user, gender: 'f') }
              let(:user1) { FactoryGirl.create(:user, gender: 'f') }
              let(:user1) { FactoryGirl.create(:user, gender: 'f') }
              let(:user1) { FactoryGirl.create(:user, gender: 'f') }
              let(:user1) { FactoryGirl.create(:user, gender: 'f') }
            end

          Only first line I wrote.. then I did Shift + v, then yanked and then 7p. These many action created the above all similar lines. Now I am looking for a trick, so that I can make all user1(s), in one shot like user1-user7. Hope I am able tell you people about my expectation :-) Is this really possible ? or manually *r* command is the only trick to replace each 1 to 2,3,4 increasing order ?
           
          Regards,
          Arup Rakshit

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

          --
          --
          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
          ... Dr. Chip s VisIncr script is the go-to for what you describe: http://vim.sourceforge.net/scripts/script.php?script_id=670 -tim -- -- You received this
          Message 4 of 7 , Jul 2, 2014
          • 0 Attachment
            On 2014-07-02 20:31, Arup Rakshit wrote:
            >   describe ".employee_learning" do
            >     let(:user1) { FactoryGirl.create(:user, gender: 'f') }
            >     let(:user1) { FactoryGirl.create(:user, gender: 'f') }
            >     let(:user1) { FactoryGirl.create(:user, gender: 'f') }
            >     let(:user1) { FactoryGirl.create(:user, gender: 'f') }
            >     let(:user1) { FactoryGirl.create(:user, gender: 'f') }
            >     let(:user1) { FactoryGirl.create(:user, gender: 'f') }
            >     let(:user1) { FactoryGirl.create(:user, gender: 'f') }
            >     let(:user1) { FactoryGirl.create(:user, gender: 'f') }
            >   end

            Dr. Chip's "VisIncr" script is the go-to for what you describe:

            http://vim.sourceforge.net/scripts/script.php?script_id=670

            -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.
          • Tim Chase
            ... which assumes that the lines are contiguous. -tim -- -- You received this message from the vim_use maillist. Do not top-post! Type your reply below the
            Message 5 of 7 , Jul 2, 2014
            • 0 Attachment
              On 2014-07-02 07:47, Tim Chase wrote:
              > On 2014-07-02 20:31, Arup Rakshit wrote:
              > >   describe ".employee_learning" do
              > >     let(:user1) { FactoryGirl.create(:user, gender: 'f') }
              > >     let(:user1) { FactoryGirl.create(:user, gender: 'f') }
              > >     let(:user1) { FactoryGirl.create(:user, gender: 'f') }
              > >     let(:user1) { FactoryGirl.create(:user, gender: 'f') }
              > >     let(:user1) { FactoryGirl.create(:user, gender: 'f') }
              > >     let(:user1) { FactoryGirl.create(:user, gender: 'f') }
              > >     let(:user1) { FactoryGirl.create(:user, gender: 'f') }
              > >     let(:user1) { FactoryGirl.create(:user, gender: 'f') }
              > >   end
              >
              > Dr. Chip's "VisIncr" script is the go-to for what you describe:
              >
              > http://vim.sourceforge.net/scripts/script.php?script_id=670

              Alternatively, for a one-off, you can visually select the lines do:

              :'<,'>s/\d\+/\=line('.')+1-line("'<")

              which assumes that the lines are contiguous.

              -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.
            • Conner McDaniel
              I would try to increment it when copying the line. For example (with the cursor on the second line of: describe .employee_learning do let(:user1) {
              Message 6 of 7 , Jul 2, 2014
              • 0 Attachment
                I would try to increment it when copying the line. For example (with the
                cursor on the second line of:

                describe ".employee_learning" do
                let(:user1) { FactoryGirl.create(:user, gender: 'f') }
                end

                Try 'qqYp<C-a>q5@q'.

                - Conner


                On Wed, Jul 02, 2014 at 08:31:42PM +0800, Arup Rakshit wrote:
                >Hi Suppose,
                >
                >I have below data :
                >
                >  describe ".employee_learning" do
                >    let(:user1) { FactoryGirl.create(:user, gender: 'f') }
                >    let(:user1) { FactoryGirl.create(:user, gender: 'f') }
                >    let(:user1) { FactoryGirl.create(:user, gender: 'f') }
                >    let(:user1) { FactoryGirl.create(:user, gender: 'f') }
                >    let(:user1) { FactoryGirl.create(:user, gender: 'f') }
                >    let(:user1) { FactoryGirl.create(:user, gender: 'f') }
                >    let(:user1) { FactoryGirl.create(:user, gender: 'f') }
                >    let(:user1) { FactoryGirl.create(:user, gender: 'f') }
                >  end
                >
                >Only first line I wrote.. then I did Shift + v, then yanked and then 7p. These many action created the above all similar lines. Now I am looking for a trick, so that I can make all user1(s), in one shot like user1-user7. Hope I am able tell you people about my expectation :-) Is this really possible ? or manually *r* command is the only trick to replace each 1 to 2,3,4 increasing order ?

                >Regards,
                >Arup Rakshit
                >
                >--
                >--
                >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.

                --
                --
                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.
              • John Beckett
                ... You have good answers, but you might want to see the tip: http://vim.wikia.com/wiki/Making_a_list_of_numbers John -- -- You received this message from the
                Message 7 of 7 , Jul 2, 2014
                • 0 Attachment

                  Arup Rakshit wrote:

                  > replace by the numbera in ascending order ?

                   

                  You have good answers, but you might want to see the tip:

                  http://vim.wikia.com/wiki/Making_a_list_of_numbers

                   

                  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

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