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

RE: searching using motions

Expand Messages
  • HALIM,SALMAN (HP-NewJersey,ex2)
    I use the following mapping myself: vmap * yy:let @/= ( . @y . ) This has the advantage (for me) of not moving the cursor (stick an n at the end
    Message 1 of 6 , May 1, 2002
    • 0 Attachment
      I use the following mapping myself:

      vmap * "yy:let @/='\(' . @y . '\)'<cr>

      This has the advantage (for me) of not moving the cursor (stick an 'n'
      at the end for that to happen); however, it is simple and corrupts the y
      register (I never use it elsewhere so I don't care to save and restore
      it) -- you can't yank directly into the / register. Also, it won't work
      if you have special characters you want to search (it doesn't escape the
      characters so magical characters retain their magical value).


      --
      "The time has come," the walrus said, "to talk of many things. Of shoes
      and ships and sealing wax, of cabbages and kings. And why the sea is
      boiling hot, and whether pigs have wings!"
      Lewis Carroll, Alice

      Salman Halim
      Current Product Engineer
      HP Bluestone


      -----Original Message-----
      From: Scott LaBounty [mailto:slabounty@...]
      Sent: Wednesday, May 01, 2002 1:26 PM
      To: 'Tim O. Gunter'
      Cc: vim@...
      Subject: RE: searching using motions


      Tim,

      Try "*3yw to yank the 3 words into the * buffer (or you can use any of your
      other favorite buffers). Then:

      /<cntl>r*

      type the / to search then <cntl>r followed by the buffer that you've yanked.
      This should do what you want.

      Scott LaBounty
      Netaphor Software, Inc.

      -----Original Message-----
      From: Tim O. Gunter [mailto:tgunter@...]
      Sent: Wednesday, May 01, 2002 10:20 AM
      To: vim@...
      Subject: searching using motions


      i would like to be able to search for a string in using motions to select
      the string from the cursors current position. for example i would like
      to be able to type something like "*3w<cr>" to highlight the next three
      words and search for all occurrences of them in the current buffer.
      is there anyway to do this? the "*" and "#" commands dont support motions,
      is there any other command that does?

      thanks
      -tim
    • Thomas S. Urban
      ... You can do it with the combination of a mapping and a function. * starts the function, which gets motion up until enter, which you can see on the input
      Message 2 of 6 , May 1, 2002
      • 0 Attachment
        On Wed, May 01, 2002 at 10:20:22 -0700, Tim O. Gunter sent 0.4K bytes:
        > i would like to be able to search for a string in using motions to select
        > the string from the cursors current position. for example i would like
        > to be able to type something like "*3w<cr>" to highlight the next three
        > words and search for all occurrences of them in the current buffer.
        > is there anyway to do this? the "*" and "#" commands dont support motions,
        > is there any other command that does?

        You can do it with the combination of a mapping and a function. '*'
        starts the function, which gets motion up until enter, which you can see
        on the input line, then it searches for the next occurence:

        function! SearchMotion()
        let motion = input("motion: ")
        execute "normal v" . motion . '"sy'
        let @/ = @s
        normal nn
        endfunction

        nnoremap * :call SearchMotion()<CR>

        Scott

        --
        If a can of Alpo costs 38 cents, would it cost $2.50 in Dog Dollars?
      • Gary Johnson
        ... Here is yet another mapping that does that (contributed to this list by someone else several months ago): Search for the highlighted text. vmap g/
        Message 3 of 6 , May 1, 2002
        • 0 Attachment
          On Wed, May 01, 2002 at 10:20:22AM -0700, Tim O. Gunter wrote:
          > i would like to be able to search for a string in using motions to select
          > the string from the cursors current position. for example i would like
          > to be able to type something like "*3w<cr>" to highlight the next three
          > words and search for all occurrences of them in the current buffer.
          > is there anyway to do this? the "*" and "#" commands dont support motions,
          > is there any other command that does?

          Here is yet another mapping that does that (contributed to this list by
          someone else several months ago):

          " Search for the highlighted text.
          vmap g/ y/<C-R>"<CR>

          Gary

          --
          Gary Johnson | Agilent Technologies
          garyjohn@... | Spokane, Washington, USA
        • Thomas S. Urban
          ... Note that both this and the function I posted earlier will not work right when certain special characters are present in the text that will be searched
          Message 4 of 6 , May 2, 2002
          • 0 Attachment
            On Wed, May 01, 2002 at 23:21:02 -0700, Gary Johnson sent 0.7K bytes:
            > On Wed, May 01, 2002 at 10:20:22AM -0700, Tim O. Gunter wrote:
            > > i would like to be able to search for a string in using motions to select
            > > the string from the cursors current position. for example i would like
            > > to be able to type something like "*3w<cr>" to highlight the next three
            > > words and search for all occurrences of them in the current buffer.
            > > is there anyway to do this? the "*" and "#" commands dont support motions,
            > > is there any other command that does?
            >
            > Here is yet another mapping that does that (contributed to this list by
            > someone else several months ago):
            >
            > " Search for the highlighted text.
            > vmap g/ y/<C-R>"<CR>

            Note that both this and the function I posted earlier will not work
            right when certain special characters are present in the text that will
            be searched for. Those characters should be escaped. Here is what I
            have in my vimrc for searching for visually selected text:

            vnoremap ;sn "sy:let @s = escape (@s, '^~/.*[]')<CR>/<C-R>s<CR>


            Scott

            --
            Blessed is he who expects nothing, for he shall never be disappointed.
            -- Alexander Pope
          Your message has been successfully submitted and would be delivered to recipients shortly.