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

Re: S&R question

Expand Messages
  • Marcin Komorowski
    This is an excellent question and I would love to know if it can be done in pure vim. ... Cheers, Marcin ... From: Eric Leenman To:
    Message 1 of 18 , Sep 30, 2005
    • 0 Attachment
      This is an excellent question and I would love to know if it can be done in
      pure vim.

      I tend to do it by piping the content through grep, like this:
      :%!grep -v 'AAA.*BBB'

      Cheers,
      Marcin

      ----- Original Message -----
      From: "Eric Leenman" <ELeenman@...>
      To: "vim" <vim@...>
      Sent: Friday, September 30, 2005 3:57 AM
      Subject: S&R question


      > Hi,
      >
      > How do you search and delete lines that contain contain AAA first and
      > secondly BBB in the line as below?
      >
      > AAA vwxyz(10) BBB blabla
      > AAA def(12) BBB talktalktalk
      >
      > Rgds,
      >
      > Eric
      >
      >
      > Disclaimer; The information contained in this communication is
      > confidential
      > and may be legally privileged. It is intended solely for the use of the
      > individual
      > or entity to whom it is addressed and others authorized to recieve it.
      > Use of this information, in whatever way, by others is strictly prohibited
      > and may be unlawful. GREEFA does not accept legal responsibility
      > for this e-mail message due to the insecure nature of internet
      > communications.
      >
    • Marcin Komorowski
      And there it is..... ;) Pete, your pattern only works for lines that start with AAA, also you do not need .*$ since the :g command by default operates on
      Message 2 of 18 , Sep 30, 2005
      • 0 Attachment
        And there it is..... ;)

        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

        Cheers,
        Marcin

        ----- Original Message -----
        From: "Pete Johns" <paj-vim@...>
        To: "vim" <vim@...>
        Sent: Friday, September 30, 2005 4:04 AM
        Subject: Re: S&R question


        > On Fri, 2005-09-30 at 09:57:18 +0200, Eric Leenman sent:
        >>Hi,
        >>
        > Hello, there!
        >
        >
        >>How do you search and delete lines that contain contain AAA
        >>first and secondly BBB in the line as below?
        >>
        > This is the way that I would do it:
        >
        > :g/^AAA.*BBB.*$/d
        >
        > See:
        >
        > :help :global
        >
        > Hope this helps;
        >
        >
        > --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>
        >
      • Tim Chase
        ... This will find & delete lines where the AAA is the first thing on the line. If you just want AAA preceeding BBB anywhere on the line (even if stuff
        Message 3 of 18 , Sep 30, 2005
        • 0 Attachment
          >>How do you search and delete lines that contain contain AAA
          >>first and secondly BBB in the line as below?
          >
          > This is the way that I would do it:
          >
          > :g/^AAA.*BBB.*$/d

          This will find & delete lines where the "AAA" is the first thing
          on the line. If you just want "AAA" preceeding "BBB" anywhere on
          the line (even if stuff preceeds the "AAA"), you can do

          :g/AAA.*BBB/d

          Additionally, since you're deleting the whole line, the ".*$" is
          a bit superflouous. If the "AAA.*BBB" matches (whether anchored
          at the beginning of the line with the "^" or not), the line, and
          its remainder (the stuff after the "BBB") will be deleted.

          And one other thing that might be helpful is if you want the
          *word* "AAA" and "BBB", but not if they exist in other words, you
          can wrap them in \<...\> such as

          :g/\<AAA\>.*\<BBB\>/d

          Hope this helps,

          -tim
        • Charles E. Campbell, Jr.
          ... Regards, Chip Campbell
          Message 4 of 18 , Sep 30, 2005
          • 0 Attachment
            Eric Leenman wrote:

            >How do you search and delete lines that contain contain AAA first and
            >secondly BBB in the line as below?
            >
            >AAA vwxyz(10) BBB blabla
            >AAA def(12) BBB talktalktalk
            >
            >

            :g/AAA.*BBB/d

            Regards,
            Chip Campbell
          • 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 5 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 6 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 7 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 8 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 9 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 10 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 11 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 12 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.