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

Re: S&R question

Expand Messages
  • Pete Johns
    ... Indeed, you are correct, Marcin. I included the caret at the beginning of the pattern as in your inxample all of the lines began with AAA. Like you say,
    Message 1 of 18 , Oct 1, 2005
    • 0 Attachment
      On Fri, 2005-09-30 at 08:54:46 -0400, Marcin Komorowski sent:
      >Pete, your pattern only works for lines that start with AAA,
      >also you do not need '.*$' since the :g command by default
      >operates on whole lines that match the search pattern, so this
      >is the simplest pattern for AAA starting anywhere in the line:
      >:g/AAA.*BBB/d
      >
      Indeed, you are correct, Marcin.

      I included the caret at the beginning of the pattern as in your
      inxample all of the lines began with AAA.

      Like you say, the ".*$" is superflous, but I tend to include such
      things for completeness. I should have mentioned this in my
      original response.

      Tim Chase raises some good points in his response, too.

      With Vim there is usually more than one solution to a given
      problem, I'm glad that you have found at least one!


      Best;


      --paj

      --
      Pete Johns <http://johnsy.com/>
      Tel/Fax numbers and IM information: <http://johnsy.com/contact/>
      Pete's iPod R.I.P. <http://johnsy.com/blog/?entry=20050928152608>
    • Eric Leenman
      Hi, I have a file like this: blabla PIN_A zzzzzzz PIN_C xxx PIN_B I want to sort this file on word PIN. How do I do this so that the result looks like: blabla
      Message 2 of 18 , Oct 25, 2007
      • 0 Attachment
        Hi,

        I have a file like this:

        blabla PIN_A
        zzzzzzz PIN_C
        xxx PIN_B


        I want to sort this file on word PIN.
        How do I do this so that the result looks like:

        blabla PIN_A
        xxx PIN_B
        zzzzzzz PIN_C

        Best regards,

        Eric

        --~--~---------~--~----~------------~-------~--~----~
        You received this message from the "vim_use" maillist.
        For more information, visit http://www.vim.org/maillist.php
        -~----------~----~----~----~------~----~------~--~---
      • Tony Mechelynck
        ... see :help :sort Best regards, Tony. -- Alex Haley was adopted! --~--~---------~--~----~------------~-------~--~----~ You received this message from the
        Message 3 of 18 , Oct 25, 2007
        • 0 Attachment
          Eric Leenman wrote:
          > Hi,
          >
          > I have a file like this:
          >
          > blabla PIN_A
          > zzzzzzz PIN_C
          > xxx PIN_B
          >
          >
          > I want to sort this file on word PIN.
          > How do I do this so that the result looks like:
          >
          > blabla PIN_A
          > xxx PIN_B
          > zzzzzzz PIN_C
          >
          > Best regards,
          >
          > Eric

          :1,$sort /^.\{-}\<PIN_/

          see ":help :sort"


          Best regards,
          Tony.
          --
          Alex Haley was adopted!

          --~--~---------~--~----~------------~-------~--~----~
          You received this message from the "vim_use" maillist.
          For more information, visit http://www.vim.org/maillist.php
          -~----------~----~----~----~------~----~------~--~---
        • Michael F. Lamb
          ... I didn t know how to do this a moment ago, but it s all described quite well in :h sorting. Had you tried that?
          Message 4 of 18 , Oct 25, 2007
          • 0 Attachment
            > I want to sort this file on word PIN.

            :%sort /PIN.*/ r

            I didn't know how to do this a moment ago, but it's all described quite
            well in :h sorting. Had you tried that?

            --~--~---------~--~----~------------~-------~--~----~
            You received this message from the "vim_use" maillist.
            For more information, visit http://www.vim.org/maillist.php
            -~----------~----~----~----~------~----~------~--~---
          • dado
            ... Me neither! I ve been using !sort all this time. So I quickly change my mappings and menus (I do a lot of sorting) to the internal sort. Now I have a
            Message 5 of 18 , Oct 26, 2007
            • 0 Attachment
              On Oct 25, 4:24 am, "Michael F. Lamb" <m...@...> wrote:
              > > I want to sort this file on word PIN.
              >
              > :%sort /PIN.*/ r
              >
              > I didn't know how to do this a moment ago, but it's all described quite
              > well in :h sorting. Had you tried that?

              Me neither! I've been using !sort all this time.
              So I quickly change my mappings and menus (I do a lot of sorting) to
              the internal sort.

              Now I have a question (sorry for the highjacking )

              How can I sort by the current column?
              I've tried many variations but none worked.
              I think this encapsulates what I'm trying to do

              :exe "sort /\%" . col(".") . "c.*/ r"

              but it seems I can't :exe even with an arbitrary column, as the
              following also fails.

              :exe "sort /\%20c.*/ r"

              whereas the sort command by itself works.

              Am I going all wrong about this?


              Thanks.
              dado


              --~--~---------~--~----~------------~-------~--~----~
              You received this message from the "vim_use" maillist.
              For more information, visit http://www.vim.org/maillist.php
              -~----------~----~----~----~------~----~------~--~---
            • A.Politz
              ... Use single quotes or escape backslashes. -ap -- Ich hab geträumt, der Krieg wär vorbei. --~--~---------~--~----~------------~-------~--~----~ You
              Message 6 of 18 , Oct 26, 2007
              • 0 Attachment
                dado wrote:

                >
                >On Oct 25, 4:24 am, "Michael F. Lamb" <m...@...> wrote:
                >
                >
                >>>I want to sort this file on word PIN.
                >>>
                >>>
                >>:%sort /PIN.*/ r
                >>
                >>I didn't know how to do this a moment ago, but it's all described quite
                >>well in :h sorting. Had you tried that?
                >>
                >>
                >
                >Me neither! I've been using !sort all this time.
                >So I quickly change my mappings and menus (I do a lot of sorting) to
                >the internal sort.
                >
                >Now I have a question (sorry for the highjacking )
                >
                >How can I sort by the current column?
                >I've tried many variations but none worked.
                >I think this encapsulates what I'm trying to do
                >
                >:exe "sort /\%" . col(".") . "c.*/ r"
                >
                >but it seems I can't :exe even with an arbitrary column, as the
                >following also fails.
                >
                >:exe "sort /\%20c.*/ r"
                >
                >whereas the sort command by itself works.
                >
                >Am I going all wrong about this?
                >
                >
                >Thanks.
                >dado
                >
                >
                >>
                >
                >
                Use single quotes or escape backslashes.

                -ap

                --
                Ich hab geträumt, der Krieg wär vorbei.


                --~--~---------~--~----~------------~-------~--~----~
                You received this message from the "vim_use" maillist.
                For more information, visit http://www.vim.org/maillist.php
                -~----------~----~----~----~------~----~------~--~---
              • Tony Mechelynck
                ... You could use the pattern as a skip pattern ... I haven t tested the above, but it ought to work even with short lines (which should sort to the top
                Message 7 of 18 , Oct 26, 2007
                • 0 Attachment
                  dado wrote:
                  >
                  >
                  > On Oct 25, 4:24 am, "Michael F. Lamb" <m...@...> wrote:
                  >>> I want to sort this file on word PIN.
                  >> :%sort /PIN.*/ r
                  >>
                  >> I didn't know how to do this a moment ago, but it's all described quite
                  >> well in :h sorting. Had you tried that?
                  >
                  > Me neither! I've been using !sort all this time.
                  > So I quickly change my mappings and menus (I do a lot of sorting) to
                  > the internal sort.
                  >
                  > Now I have a question (sorry for the highjacking )
                  >
                  > How can I sort by the current column?
                  > I've tried many variations but none worked.
                  > I think this encapsulates what I'm trying to do
                  >
                  > :exe "sort /\%" . col(".") . "c.*/ r"
                  >
                  > but it seems I can't :exe even with an arbitrary column, as the
                  > following also fails.
                  >
                  > :exe "sort /\%20c.*/ r"
                  >
                  > whereas the sort command by itself works.
                  >
                  > Am I going all wrong about this?
                  >
                  >
                  > Thanks.
                  > dado

                  You could use the pattern as a "skip" pattern

                  :command -nargs=0 -bar ColSort exe 'sort /.*\%<' . virtcol('.') . 'v/'

                  I haven't tested the above, but it ought to work even with short lines (which
                  should sort to the top IIUC) and hard tabs (where, IIUC, the first character
                  after the tab is used if, on a line other than the cursor line, the cursor
                  column falls in the middle of a hard tab).

                  Note the use of single quotes to avoid the need for backslash-escaping the
                  backslash.


                  Best regards,
                  Tony.
                  --
                  Condoms are like listening to a symphony with cotton in your ears.

                  --~--~---------~--~----~------------~-------~--~----~
                  You received this message from the "vim_use" maillist.
                  For more information, visit http://www.vim.org/maillist.php
                  -~----------~----~----~----~------~----~------~--~---
                • Charles E Campbell Jr
                  ... The tip is pre-7.0, but it still works: How to sort using visual blocks http://vim.sourceforge.net/tips/tip.php?tip_id=588 (except change erols addresses
                  Message 8 of 18 , Oct 26, 2007
                  • 0 Attachment
                    dado wrote:

                    >How can I sort by the current column?
                    >I've tried many variations but none worked.
                    >
                    >
                    The tip is pre-7.0, but it still works:

                    "How to sort using visual blocks"
                    http://vim.sourceforge.net/tips/tip.php?tip_id=588

                    (except change erols addresses to http://mysite.verizon.net/astronaut/...)

                    Regards,
                    Chip Campbell


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