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

Making :grep easier to use

Expand Messages
  • David Frey
    Often times I am looking at a file and there is a certain string sitting infront of me that I want to grep for. Right now, I go into command mode and type ...
    Message 1 of 5 , Dec 6, 2005
    • 0 Attachment
      Often times I am looking at a file and there is a certain string sitting
      infront of me that I want to grep for.

      Right now, I go into command mode and type
      :grep "some_string" *.extension

      Is it possible to yank some_string and then paste it into the command?
      It would save me a lot of typing when I am grepping for strings.

      Thanks
    • Tim Chase
      ... To immediately answer your question, if you ve yanked the text into a register, you can use control+R followed by the name of that register (by default,
      Message 2 of 5 , Dec 6, 2005
      • 0 Attachment
        > Is it possible to yank some_string and then paste it into the
        > command? It would save me a lot of typing when I am grepping
        > for strings.

        To immediately answer your question, if you've yanked the text
        into a register, you can use control+R followed by the name of
        that register (by default, the double-quote) and it will put the
        text you yanked onto the command line.

        :help c_^R

        In addition, if you just want a particular Word or WORD under the
        cursor, you can use control+R followed by control+W (for a Word)
        or followed by control+A (for the WORD under the cursor). More
        info can be found at

        :help ^R^W

        where you can also read about the ^R^W and ^R^P variants which
        will pull in the filename (with and without path respectively.

        There are also variants of the ^R^W family of items with 2x the
        ^R prefix to enter the item literally

        :help c_^R^R

        for more on that.

        Thus, you can type "colon gee are ee pee space double-quote
        control+R double-quote double-quote space asterisk period (your
        extension)" to get the most recently yanked text in those quotes.

        Hope this gives you some options to easily do what you want.

        -tim
      • Mathias Michaelis
        David ... The command ... searches for the word under the cursor in all files that have the same extension as the current file. Here, you have to type
        Message 3 of 5 , Dec 7, 2005
        • 0 Attachment
          David

          > Often times I am looking at a file and there is a certain string
          > sitting infront of me that I want to grep for.
          >
          The command

          :grep <cword> *.%:e

          searches for the word under the cursor in all files that have the
          same extension as the current file. Here, you have to type <cword>
          literally (as greater-than, c, w, o, r, d, less-than), it is not a
          special key.

          You may want to create a map as in

          :map <Leader>g :grep <cword> *.%:e

          Best regards

          Mathias
        • thomas scott urban
          ... On the command line insert the contents of the unnamed yank buffer.
          Message 4 of 5 , Jul 2, 2006
          • 0 Attachment
            On Tue, 2005-12-06 at 12:32 -0800, David Frey wrote:
            > Often times I am looking at a file and there is a certain string sitting
            > infront of me that I want to grep for.
            >
            > Right now, I go into command mode and type
            > :grep "some_string" *.extension
            >
            > Is it possible to yank some_string and then paste it into the command?
            > It would save me a lot of typing when I am grepping for strings.

            On the command line

            <C-R>"

            insert the contents of the unnamed yank buffer.

            :he c_<C-R>


            > Thanks
          • Stefan Karlsson
            A bit off-topic, but in addition to yank and paste (e.g. ) you can use to insert the word under the cursor. -- Stefan
            Message 5 of 5 , Jul 2, 2006
            • 0 Attachment
              A bit off-topic, but in addition to yank and paste (e.g. <c-r>") you can
              use <c-r><c-w> to insert the word under the cursor.

              --
              Stefan
            Your message has been successfully submitted and would be delivered to recipients shortly.