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

Re: searching for consecutive words under cursor

Expand Messages
  • Tim Chase
    ... This (as you may have discovered) searches for the third match of the single word under the cursor. ... Knowing were to delimit and how many words/Words to
    Message 1 of 3 , Sep 2, 2011
    • 0 Attachment
      On 09/02/11 06:43, John Goche wrote:
      > foo.bar.cat.nav
      >
      > the cursor is over "bar". I want to search for "bar.cat".
      > That should be three words including the dot. I would
      > like to give the command
      >
      > 3*

      This (as you may have discovered) searches for the third match of
      the single word under the cursor.

      > but it does not work as I wish. Instead I have to specify
      > the '/' (forward slash) and type bar.cat manually.
      >
      > Anyone have a solution or should I submit a feature request?

      Knowing were to delimit and how many words/Words to find becomes
      a bit tricky. However, for the most part, you can yank the terms
      and then paste them into the search expression. So as above, you
      can do something like

      y3iw
      /<c-r>"

      which will yank 3 "inner words" (if the cursor is, as you say,
      over "bar" and you want to search for "bar.cat", as "bar", ".",
      and "cat" are each found as a word) and then control-R followed
      by the double-quote (to paste the scratch register into which the
      words were yanked). This doesn't escape the metachars, so the
      search will then find not only "bar.cat" but "barxcat" or
      "barfcat". There are ways to escape them, but you might then
      want to investigate searching for visually-selected text[1].
      This would allow you to use the mapping at that link to do

      v3iw*

      to visually select the desired 3 words and then search for the
      highlighted content.

      -tim

      [1]
      http://vim.wikia.com/wiki/Search_for_visually_selected_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
    • Christian Brabandt
      Hi John! ... You could use g* which works like * but doesn t add word boundaries to the search term. This way, it should also match at words starting with bar
      Message 2 of 3 , Sep 3, 2011
      • 0 Attachment
        Hi John!

        On Fr, 02 Sep 2011, John Goche wrote:

        > Hello,
        >
        > I am used to searching for the word under the cursor
        > by hitting the '*' character and then navigating with the
        > 'n' (next match) and 'N' (previous match) commands.
        > But now suppose I have more than one word under
        > the cursor, eg.
        >
        > foo.bar.cat.nav
        >
        > the cursor is over "bar". I want to search for "bar.cat".
        > That should be three words including the dot. I would
        > like to give the command
        >
        > 3*
        >
        > but it does not work as I wish. Instead I have to specify
        > the '/' (forward slash) and type bar.cat manually.
        >
        > Anyone have a solution or should I submit a feature request?

        You could use g* which works like * but doesn't add word boundaries to
        the search term. This way, it should also match at words starting with
        bar

        regards,
        Christian

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