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

Re: delete last character of multiple lines

Expand Messages
  • Phil Dobbin
    ... Does the . replace a character with nothing? Cheers, Phil... -- currently (ab)using CentOS 5.9 & 6.4, Debian Squeeze & Wheezy, Fedora Beefy, Spherical &
    Message 1 of 10 , May 8, 2013
    • 0 Attachment
      On 08/05/2013 18:29, Jürgen Krämer wrote:

      > :
      >>> what should i do in order to delete last character of multiple lines?\
      >>
      >> How about visually selecting the lines and then:
      >>
      >> :'<,'>norm! $x
      >
      > or
      >
      > :'<,'>s/.$//

      Does the '.' replace a character with nothing?

      Cheers,

      Phil...

      --
      currently (ab)using
      CentOS 5.9 & 6.4, Debian Squeeze & Wheezy, Fedora Beefy, Spherical &
      That Damn Cat, Lubuntu 12.10, OS X Snow Leopard, Ubuntu Precise, Quantal
      & Raring
      GnuGPG Key : http://phildobbin.org/publickey.asc


      --
      --
      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/groups/opt_out.
    • Tim Chase
      ... This is the method I d default to. It s a standard search/replace command. The pattern searched for is any one character ( . ) at the end of the line
      Message 2 of 10 , May 8, 2013
      • 0 Attachment
        On 2013-05-08 19:15, Phil Dobbin wrote:
        > On 08/05/2013 18:29, Jürgen Krämer wrote:
        > > :'<,'>s/.$//
        >
        > Does the '.' replace a character with nothing?

        This is the method I'd default to. It's a standard search/replace
        command. The pattern searched for is "any one character ('.') at the
        end of the line ('$')" and replaces it with nothing (there's nothing
        between the 2nd and 3rd slashes as a replacement).

        You can visualize it by making the replacement something like "XXXX":

        :'<,'>s/.$/XXXX

        (the trailing "/" is optional when you don't have any flags to
        include). You can then "u"ndo that to return to your original
        document. Also, when there are no flags *AND* no replacement value,
        the whole thing can be shortened to just

        :'<,'>s/.$

        -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/groups/opt_out.
      • Phil Dobbin
        ... Many thanks, Tim. Cheers, Phil... -- currently (ab)using CentOS 5.9 & 6.4, Debian Squeeze & Wheezy, Fedora Beefy, Spherical & That Damn Cat, Lubuntu 12.10,
        Message 3 of 10 , May 8, 2013
        • 0 Attachment
          On 08/05/2013 19:46, Tim Chase wrote:

          > On 2013-05-08 19:15, Phil Dobbin wrote:
          >> On 08/05/2013 18:29, Jürgen Krämer wrote:
          >>> :'<,'>s/.$//
          >>
          >> Does the '.' replace a character with nothing?
          >
          > This is the method I'd default to. It's a standard search/replace
          > command. The pattern searched for is "any one character ('.') at the
          > end of the line ('$')" and replaces it with nothing (there's nothing
          > between the 2nd and 3rd slashes as a replacement).
          >
          > You can visualize it by making the replacement something like "XXXX":
          >
          > :'<,'>s/.$/XXXX
          >
          > (the trailing "/" is optional when you don't have any flags to
          > include). You can then "u"ndo that to return to your original
          > document. Also, when there are no flags *AND* no replacement value,
          > the whole thing can be shortened to just
          >
          > :'<,'>s/.$

          Many thanks, Tim.

          Cheers,

          Phil...

          --
          currently (ab)using
          CentOS 5.9 & 6.4, Debian Squeeze & Wheezy, Fedora Beefy, Spherical &
          That Damn Cat, Lubuntu 12.10, OS X Snow Leopard, Ubuntu Precise, Quantal
          & Raring
          GnuGPG Key : http://phildobbin.org/publickey.asc


          --
          --
          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/groups/opt_out.
        • yoni kessler
          thanks allot! I m a bit familiar with regex, but can you please explain what exactly does :
          Message 4 of 10 , May 8, 2013
          • 0 Attachment
            thanks allot!

            I'm a bit familiar with regex,
            but can you please explain what exactly does :'<,'> means?

            thanks again

            --
            --
            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/groups/opt_out.
          • Nicolas Dermine
            ... Hi Yoni, The
            Message 5 of 10 , May 8, 2013
            • 0 Attachment



              On Thu, May 9, 2013 at 12:44 AM, yoni kessler <yoni101kessler@...> wrote:
              thanks allot!

              I'm a bit familiar with regex,
              but can you please explain what exactly does   :'<,'>  means?

              Hi Yoni,

              The '<,'> range stands for the current (or last) visual selection.

              When you have a visual selection and type :, the command line automatically gets this '<,'> range avec the colon.

              If you wanted to apply the search and replace command on the whole file, you would use % to specify the range of the s/.$ command :

              :%s/.$

              To do that only on the last/current visual selection :

              :'<,'>s/.$

              To do that on lines 2 to 4 :

              :2,4s/.$

              If you type :helpgrep '<,'> (and then :cn to navigate to the next occurrences found in the documentation) you can read more about it.
              For example this in usr_10.txt :

              ```
              The '< and '> are actually marks, placed at the start and end of the Visual
              selection.  The marks remain at their position until another Visual selection
              is made.  Thus you can use the "'<" command to jump to position where the
              Visual area started.  And you can mix the marks with other items: >

              :'>,$

              This addresses the lines from the end of the Visual area to the end of the
              file.
              ```

              nico






              thanks again

              --
              --
              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/groups/opt_out.



              --
              --
              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/groups/opt_out.
               
               
            • Tim Chase
              ... That s a range as defined by two marks, the
              Message 6 of 10 , May 8, 2013
              • 0 Attachment
                > but can you please explain what exactly does :'<,'> means?

                That's a range as defined by two marks, the

                '<

                mark (meaning the starting line of a visual selection)

                ,

                through the

                '>

                mark (meaning the ending line of a visual selection).

                Vim supports an incredibly powerful declaration of ranges which you
                can read about at

                :help :range

                which allows for absolute and relative addressing, including relative
                to previous addresses such as

                :1/CHAPTER/+2,$?APPENDIX?-3

                which starts on line 1, searches forward for "CHAPTER", then moves
                forward 2 lines from there to start the range, and then starts at the
                bottom of the file ("$"), searches backwards for "APPENDIX", and then
                moves 3 lines back from that match.

                -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/groups/opt_out.
              • James
                ... Hi Yoni, I m not a regex expert. I usually do that sort of thing with a macro. qq // start recording macro q $ // move cursor to end
                Message 7 of 10 , May 9, 2013
                • 0 Attachment
                  On May 8, 10:01 am, yoni kessler <yoni101kess...@...> wrote:
                  >
                  > I tried to delete the last character of multiple lines in the following way:

                  Hi Yoni,

                  I'm not a regex expert. I usually do that sort of thing with a macro.

                  qq // start recording macro 'q'
                  $ // move cursor to end of current line
                  x // delete character
                  j // move down to next line
                  q // stop recording macro

                  Now you can delete the last character of ten lines starting at the
                  line containing the cursor with the following command.

                  10@q

                  James

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