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

Search characters under cursor

Expand Messages
  • rpmcmurphy
    How does one search characters under cursor? Not * which is a whole word. I am looking for something like / and then repeated typing of some special
    Message 1 of 4 , Jul 1, 2009
    • 0 Attachment
      How does one search characters under cursor? Not '*' which is a whole
      word. I am looking for something like / and then repeated typing of
      some special character, say ~, which will add the next character from
      cursor position in the file. For example say the file contains "The
      quick brown fox jumped over the lazy dog." and the cursor is
      positioned at k at the end of "quick". I want to create a search for
      "k bro" without having to type the letters. I have seen emacs users do
      it and I thought I had found a way to do it once in vim but I can't
      remember how.

      Thanks.

      --~--~---------~--~----~------------~-------~--~----~
      You received this message from the "vim_use" maillist.
      For more information, visit http://www.vim.org/maillist.php
      -~----------~----~----~----~------~----~------~--~---
    • Tim Chase
      ... You might try this pair of mappings: nnoremap :let @/=escape(getline( . )[col( . )-1], .~ ) nnoremap :let
      Message 2 of 4 , Jul 1, 2009
      • 0 Attachment
        rpmcmurphy wrote:
        > How does one search characters under cursor? Not '*' which is a whole
        > word. I am looking for something like / and then repeated typing of
        > some special character, say ~, which will add the next character from
        > cursor position in the file. For example say the file contains "The
        > quick brown fox jumped over the lazy dog." and the cursor is
        > positioned at k at the end of "quick". I want to create a search for
        > "k bro" without having to type the letters. I have seen emacs users do
        > it and I thought I had found a way to do it once in vim but I can't
        > remember how.

        You might try this pair of mappings:

        nnoremap <f4> :let @/=escape(getline('.')[col('.')-1],
        '.~\\')<cr><right>

        nnoremap <f5> :let @/.=escape(getline('.')[col('.')-1],
        '.~\\')<cr><right>


        You may have to tweak the set of characters that are escaped, but
        it should allow you to hit <f4> to start, and then <f5> to keep
        adding consecutive characters to the search pattern.

        -tim





        --~--~---------~--~----~------------~-------~--~----~
        You received this message from the "vim_use" maillist.
        For more information, visit http://www.vim.org/maillist.php
        -~----------~----~----~----~------~----~------~--~---
      • Christian Brabandt
        ... I personally would use something like this: nnoremap :norm! ayl :let @/=escape(@a, .~ ) nnoremap :norm! ayl :let
        Message 3 of 4 , Jul 1, 2009
        • 0 Attachment
          On Wed, July 1, 2009 5:20 pm, Tim Chase wrote:
          > You might try this pair of mappings:
          >
          > nnoremap <f4> :let @/=escape(getline('.')[col('.')-1],
          > '.~\\')<cr><right>
          >
          > nnoremap <f5> :let @/.=escape(getline('.')[col('.')-1],
          > '.~\\')<cr><right>
          >

          I personally would use something like this:

          nnoremap <f4> :norm! "ayl<cr>:let @/=escape(@a, '.~\\')<cr><right>
          nnoremap <f5> :norm! "ayl<cr>:let @/.=escape(@a, '.~\\')<cr><right>

          The reason is, that col('.')-1 has problems with multibyte chars and
          will return only the first byte of the char under the cursor.

          But this has the disadvantage of cluttering your "a register.

          regards,
          Christian
          --
          :wq!


          --~--~---------~--~----~------------~-------~--~----~
          You received this message from the "vim_use" maillist.
          For more information, visit http://www.vim.org/maillist.php
          -~----------~----~----~----~------~----~------~--~---
        • rpmcmurphy
          Thanks guys. Both methods work great. Am not editing multibyte so I ll save my a reg. ... --~--~---------~--~----~------------~-------~--~----~ You received
          Message 4 of 4 , Jul 1, 2009
          • 0 Attachment
            Thanks guys. Both methods work great. Am not editing multibyte so I'll
            save my "a reg.


            On Jul 1, 8:48 pm, "Christian Brabandt" <cbli...@...> wrote:
            > On Wed, July 1, 2009 5:20 pm, Tim Chase wrote:
            > > You might try this pair of mappings:
            >
            > > nnoremap <f4> :let @/=escape(getline('.')[col('.')-1],
            > > '.~\\')<cr><right>
            >
            > > nnoremap <f5> :let @/.=escape(getline('.')[col('.')-1],
            > > '.~\\')<cr><right>
            >
            > I personally would use something like this:
            >
            > nnoremap <f4> :norm! "ayl<cr>:let @/=escape(@a, '.~\\')<cr><right>
            > nnoremap <f5> :norm! "ayl<cr>:let @/.=escape(@a, '.~\\')<cr><right>
            >
            > The reason is, that col('.')-1 has problems with multibyte chars and
            > will return only the first byte of the char under the cursor.
            >
            > But this has the disadvantage of cluttering your "a register.
            >
            > regards,
            > Christian
            > --
            > :wq!
            --~--~---------~--~----~------------~-------~--~----~
            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.