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

does vi has a funtion like "grep -v"?

Expand Messages
  • skyworld
    Hi, does vi has a fuction like grep -v ? I always found I need to seach within the file with those lines which exclue specific strings. Thanks. regards -- --
    Message 1 of 10 , Jan 25, 2013
    • 0 Attachment
      Hi,

      does vi has a fuction like "grep -v"? I always found I need to seach
      within the file with those lines which exclue specific strings.
      Thanks.


      regards

      --
      --
      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
    • Jiantao Wu
      No, it does not. You can use ? or / to search. 2013/1/25 skyworld ... -- -- You received this message from the vim_use
      Message 2 of 10 , Jan 25, 2013
      • 0 Attachment
        No, it does not. You can use '?' or '/' to search.


        2013/1/25 skyworld <chenyong20000@...>
        Hi,

        does vi has a fuction like "grep -v"? I always found I need to seach
        within the file with those lines which exclue specific strings.
        Thanks.


        regards

        --
        --
        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 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
         
         
         
      • Aaron Webster
        ... Searching in vim is done with regular expressions, so I believe this is possible. For example, to search for lines with do not include string
        Message 3 of 10 , Jan 25, 2013
        • 0 Attachment
          On Fri, Jan 25, 2013 at 10:21 AM, skyworld <chenyong20000@...> wrote:
          Hi,

          does vi has a fuction like "grep -v"? I always found I need to seach
          within the file with those lines which exclue specific strings.
          Thanks.

          Searching in vim is done with regular expressions, so I believe this is possible.  For example, to search for lines with do not include "string"

              /^\(\(.*string.*\)\@!.\)*$

          See here:



          --
          Aaron Webster

          --
          --
          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
           
           
           
        • Shlomi Fish
          Hi skyworld, On Fri, 25 Jan 2013 01:21:37 -0800 (PST) ... First of all, you can use :v/re/p (Replace p with whatever). Otherwise look at negated regular
          Message 4 of 10 , Jan 25, 2013
          • 0 Attachment
            Hi skyworld,

            On Fri, 25 Jan 2013 01:21:37 -0800 (PST)
            skyworld <chenyong20000@...> wrote:

            > Hi,
            >
            > does vi has a fuction like "grep -v"? I always found I need to seach
            > within the file with those lines which exclue specific strings.
            > Thanks.
            >

            First of all, you can use :v/re/p (Replace p with whatever). Otherwise look at
            negated regular expressions in http://shlomif-tech.livejournal.com/40557.html .

            Regards,

            Shlomi Fish

            --
            -----------------------------------------------------------------
            Shlomi Fish http://www.shlomifish.org/
            Beginners Site for the Vim text editor - http://vim.begin-site.org/

            The bad thing about hardware is that it sometimes works and it sometimes
            doesn’t. The good thing about software is that it’s consistent: it always
            does not work, and it always does not work in exactly the same way.

            Please reply to list if it's a mailing list post - http://shlom.in/reply .

            --
            --
            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
          • Catalin Ciurea
            ... See the :grep command (:he :grep) in Vim. This command uses the grepprg option to check what program to call. By default is grep -n (See :he grepprg )
            Message 5 of 10 , Jan 25, 2013
            • 0 Attachment
              On Friday, January 25, 2013 11:21:37 AM UTC+2, skyworld wrote:
              > Hi,
              >
              >
              >
              > does vi has a fuction like "grep -v"? I always found I need to seach
              >
              > within the file with those lines which exclue specific strings.
              >
              > Thanks.
              >
              >
              >
              >
              >
              > regards

              See the :grep command (:he :grep) in Vim.
              This command uses the 'grepprg' option to check what program to call. By default is 'grep -n'(See :he 'grepprg')

              You can always do something like:
              set grepprg+=-v
              :grep foo *

              Check :vimgrep command also. It uses Vim regular expressions and an internal search engine. (Slower but if you are familiar with Vim re, it's a good option)

              --
              --
              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
            • Charles Campbell
              ... /^ %( %(pattern ) @!. )*$ You may find LogiPat of interest; it allows you to construct patterns using Boolean logic (not, and, or):
              Message 6 of 10 , Jan 25, 2013
              • 0 Attachment
                skyworld wrote:
                > Hi,
                >
                > does vi has a fuction like "grep -v"? I always found I need to seach
                > within the file with those lines which exclue specific strings.
                > Thanks.
                >
                Here are two methods:

                :v/pattern/p

                /^\%(\%(pattern\)\@!.\)*$

                You may find LogiPat of interest; it allows you to construct patterns
                using Boolean logic (not, and, or):
                http://www.drchip.org/astronaut/vim/index.html#LOGIPAT

                Regards,
                C Campbell

                --
                --
                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
              • skyworld
                Thanks for all of your kind reply. I will check these ways. ... -- -- You received this message from the vim_use maillist. Do not top-post! Type your reply
                Message 7 of 10 , Jan 26, 2013
                • 0 Attachment
                  Thanks for all of your kind reply. I will check these ways.

                  On Jan 25, 5:26 pm, Jiantao Wu <4576211...@...> wrote:
                  > No, it does not. You can use '?' or '/' to search.
                  >
                  > 2013/1/25 skyworld <chenyong20...@...>
                  >
                  >
                  >
                  > > Hi,
                  >
                  > > does vi has a fuction like "grep -v"? I always found I need to seach
                  > > within the file with those lines which exclue specific strings.
                  > > Thanks.
                  >
                  > > regards
                  >
                  > > --
                  > > --
                  > > 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, visithttp://www.vim.org/maillist.php- Hide quoted text -
                  >
                  > - Show quoted text -

                  --
                  --
                  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
                • Ping
                  Why not just use external grep in vim if that s what you want? ... -- -- You received this message from the vim_use maillist. Do not top-post! Type your
                  Message 8 of 10 , Jan 26, 2013
                  • 0 Attachment
                    Why not just use external grep in vim if that's what you want?
                    :[range]!grep -v



                    On Jan 25, 2013, at 7:20 AM, Catalin Ciurea <catalin.ciurea@...> wrote:

                    > On Friday, January 25, 2013 11:21:37 AM UTC+2, skyworld wrote:
                    >> Hi,
                    >>
                    >>
                    >>
                    >> does vi has a fuction like "grep -v"? I always found I need to seach
                    >>
                    >> within the file with those lines which exclue specific strings.
                    >>
                    >> Thanks.
                    >>
                    >>
                    >>
                    >>
                    >>
                    >> regards
                    >
                    > See the :grep command (:he :grep) in Vim.
                    > This command uses the 'grepprg' option to check what program to call. By default is 'grep -n'(See :he 'grepprg')
                    >
                    > You can always do something like:
                    > set grepprg+=-v
                    > :grep foo *
                    >
                    > Check :vimgrep command also. It uses Vim regular expressions and an internal search engine. (Slower but if you are familiar with Vim re, it's a good option)
                    >
                    > --
                    > --
                    > 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 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
                  • Ben Fritz
                    ... This will replace all the lines in [range] with the output of !grep. I don t think the OP wanted to DELETE the lines, just find them. The better way to
                    Message 9 of 10 , Jan 26, 2013
                    • 0 Attachment
                      On Saturday, January 26, 2013 10:34:32 AM UTC-6, ping wrote:
                      > Why not just use external grep in vim if that's what you want?
                      >
                      > :[range]!grep -v
                      >
                      >

                      This will replace all the lines in [range] with the output of !grep. I don't think the OP wanted to DELETE the lines, just find them.

                      The better way to invoke external grep for searching from Vim is with Vim's :grep command, which invokes 'grepprg' and then populates the quickfix list. 'grepprg' by default just uses grep.

                      --
                      --
                      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
                    • ping
                      ... that s a good point, but from what my experiences (test, errors), in an attempt to find the solution for this desire , I really think the external grep way
                      Message 10 of 10 , Jan 26, 2013
                      • 0 Attachment
                        On 1/26/2013 11:38 AM, Ben Fritz wrote:
                        > On Saturday, January 26, 2013 10:34:32 AM UTC-6, ping wrote:
                        >> Why not just use external grep in vim if that's what you want?
                        >>
                        >> :[range]!grep -v
                        >>
                        >>
                        > This will replace all the lines in [range] with the output of !grep. I don't think the OP wanted to DELETE the lines, just find them.
                        >
                        > The better way to invoke external grep for searching from Vim is with Vim's :grep command, which invokes 'grepprg' and then populates the quickfix list. 'grepprg' by default just uses grep.
                        >
                        that's a good point, but from what my experiences (test, errors), in an
                        attempt to find the solution for this desire , I really think the
                        external grep way is the most efficient.
                        reason:

                        1) most of time , I just want to quicky find out the wanted or
                        not-wanted (-v) lines per keyword
                        2) :[range]!grep [-v] will re-use whatever your skills of standard unix
                        tool : grep
                        3) if you don't want to "replace" but to "display", you can use
                        :[range]w !grep [-v]
                        4) but the :[range]w ! way doesn't know "scale", as the new found texts
                        won't but put in a buffer by default, (unless redirected), so you can't
                        re-fine your research based on the result.
                        5) even if you don't want to "replace" the original texts, you can
                        easily go back via "u"
                        6) and if you like what you get, but want to even re-define a new
                        search based on it, just repeat the whole process recursively.
                        7) and once done, always just recover back to original text via some
                        'u'ndos.

                        I also like the vimgrep coming with the fancy quickfix list, but that
                        looks a better usage scenario when I need to search from a bunch of
                        files (under a common dir ).

                        just my 2 cents.

                        regards
                        ping

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