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

Analog to SHIFT+Asterisk

Expand Messages
  • Hoss
    Esteemed Vim Users, One of the useful key combinations in vim is shift+asterisk, which will locate the word your cursor is on , and put that word into your /
    Message 1 of 6 , Jun 30, 2010
    • 0 Attachment
      Esteemed Vim Users,

      One of the useful key combinations in vim is shift+asterisk, which
      will locate the word your cursor is "on", and put that word into your
      "/ buffer (surrounded by \<\> word boundaries). This has the effect of
      highlighting all occurrences of that word.

      It also has the effect of jumping the cursor to the next instance of
      that word in your buffer.

      Is there an analogous key combination, that will highlight the current
      word, WITHOUT moving my cursor?

      Thanks,

      Todd

      (I know I can just shift+N afterwards, to get back where I was.
      Something more elegant?)

      --
      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
    • Benjamin R. Haskell
      ... Replace A with whatever key(s) you want to map it to. That sets the search register to start-of-word + the current word + end-of-word without actually
      Message 2 of 6 , Jun 30, 2010
      • 0 Attachment
        On Wed, 30 Jun 2010, Hoss wrote:

        > Esteemed Vim Users,
        >
        > One of the useful key combinations in vim is shift+asterisk, which
        > will locate the word your cursor is "on", and put that word into your
        > "/ buffer (surrounded by \<\> word boundaries). This has the effect of
        > highlighting all occurrences of that word.
        >
        > It also has the effect of jumping the cursor to the next instance of
        > that word in your buffer.
        >
        > Is there an analogous key combination, that will highlight the current
        > word, WITHOUT moving my cursor?

        Fun:

        :nmap A :call setreg('/','\<'.expand('<lt>cword>').'\>')<CR>

        Replace 'A' with whatever key(s) you want to map it to.

        That sets the search register to start-of-word + the current word +
        end-of-word without actually performing the search. The search doesn't
        show up in the search history (q/), though. The much-simpler:

        :nmap A *<C-O>

        will perform a star search (ha), and then go back to the prior position.
        Has the advantage of putting it in the search history but (IMO,
        significantly-worse) disadvantage of moving the cursor if the next match
        is off-screen.

        See:

        :help key-mapping
        :help :nmap
        :help expand()
        :help map.txt | /<lt> -- for why I used '<lt>' in the mapping
        :help :<cword>

        --
        Best,
        Ben

        --
        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
      • John Beckett
        ... See this tip: http://vim.wikia.com/wiki/Highlight_all_search_pattern_matches John -- You received this message from the vim_use maillist. Do not
        Message 3 of 6 , Jun 30, 2010
        • 0 Attachment
          Hoss wrote:
          > Is there an analogous key combination, that will highlight
          > the current word, WITHOUT moving my cursor?

          See this tip:
          http://vim.wikia.com/wiki/Highlight_all_search_pattern_matches

          John

          --
          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
        • Hoss
          Great. Exactly what I was looking for. -- You received this message from the vim_use maillist. Do not top-post! Type your reply below the text you are
          Message 4 of 6 , Jul 1 7:25 AM
          • 0 Attachment
            Great. Exactly what I was looking for.

            --
            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
          • BC
            ... Shift+N may be inelegant (why? I don t understand that) but I don t ... Doesn t that do what you described? - BC -- You received this message from the
            Message 5 of 6 , Jul 1 3:08 PM
            • 0 Attachment
              On Jun 30, 6:29 pm, Hoss <todd.fr...@...> wrote:

              >
              > (I know I can just shift+N afterwards, to get back where I was.
              > Something more elegant?)


              Shift+N may be inelegant (why? I don't understand that) but I don't
              see what would be wrong with a simple mapping like this:

              :map A *N

              Doesn't that do what you described?


              - BC

              --
              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
            • Gary Johnson
              ... No. The window s location in the buffer may change, which is visually jarring. The cursor s position may change, too, if it wasn t originally on the
              Message 6 of 6 , Jul 1 3:33 PM
              • 0 Attachment
                On 2010-07-01, BC wrote:
                > On Jun 30, 6:29 pm, Hoss <todd.fr...@...> wrote:
                >
                > >
                > > (I know I can just shift+N afterwards, to get back where I was.
                > > Something more elegant?)
                >
                >
                > Shift+N may be inelegant (why? I don't understand that) but I don't
                > see what would be wrong with a simple mapping like this:
                >
                > :map A *N
                >
                > Doesn't that do what you described?

                No. The window's location in the buffer may change, which is
                visually jarring. The cursor's position may change, too, if it
                wasn't originally on the first character of the word, but that's
                usually not as noticeable.

                Regards,
                Gary

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