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

adding a word to the search history

Expand Messages
  • Matteo Cavalleri
    i ve added this map to my vimrc (copied from somewhere): nnoremap * :let @/= =expand( ) :set hls it higlights the word under the
    Message 1 of 8 , Jul 11, 2013
      i've added this map to my vimrc (copied from somewhere):

      nnoremap * :let @/='\<<C-R>=expand("<cword>")<CR>\>'<CR>:set hls<CR>

      it higlights the word under the cursor but doesn't jump to the next match. it's working fine, but i discovered a little problem: it doesn't add the word to the search history, like the original '*' does. is there a way to fix this problem? i've googled a bit but haven't found anything useful...

      thanks in advance.

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

      ---
      You received this message because you are subscribed to the Google Groups "vim_use" group.
      To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
      For more options, visit https://groups.google.com/groups/opt_out.
    • Nikolay Pavlov
      ... match. it s working fine, but i discovered a little problem: it doesn t add the word to the search history, like the original * does. is there a way to
      Message 2 of 8 , Jul 11, 2013


        On Jul 11, 2013 6:05 PM, "Matteo Cavalleri" <cvlmtg@...> wrote:
        >
        > i've added this map to my vimrc (copied from somewhere):
        >
        > nnoremap * :let @/='\<<C-R>=expand("<cword>")<CR>\>'<CR>:set hls<CR>
        >
        > it higlights the word under the cursor but doesn't jump to the next match. it's working fine, but i discovered a little problem: it doesn't add the word to the search history, like the original '*' does. is there a way to fix this problem? i've googled a bit but haven't found anything useful...
        >
        > thanks in advance.

        There is histadd() function for this.

        > --
        > --
        > 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
        >
        > ---
        > You received this message because you are subscribed to the Google Groups "vim_use" group.
        > To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
        > For more options, visit https://groups.google.com/groups/opt_out.
        >
        >

        --
        --
        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
         
        ---
        You received this message because you are subscribed to the Google Groups "vim_use" group.
        To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
        For more options, visit https://groups.google.com/groups/opt_out.
         
         
      • glts
        ... I use a different approach. This clobbers the x and y marks though. nnoremap * :keepjumps normal! mxHmy`x* yzt`x Best, -- -- You received this
        Message 3 of 8 , Jul 11, 2013
          On Thursday, July 11, 2013 4:05:20 PM UTC+2, Matteo Cavalleri wrote:
          > i've added this map to my vimrc (copied from somewhere):
          >
          > nnoremap * :let @/='\<<C-R>=expand("<cword>")<CR>\>'<CR>:set hls<CR>
          >
          > it higlights the word under the cursor but doesn't jump to the next match. it's working fine, but i discovered a little problem: it doesn't add the word to the search history, like the original '*' does. is there a way to fix this problem? i've googled a bit but haven't found anything useful...

          I use a different approach. This clobbers the x and y marks though.

          nnoremap <silent> * :keepjumps normal! mxHmy`x*'yzt`x<CR>

          Best,

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

          ---
          You received this message because you are subscribed to the Google Groups "vim_use" group.
          To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
          For more options, visit https://groups.google.com/groups/opt_out.
        • Matteo Cavalleri
          thanks, i ll try the histadd() function first. i don t usually use marks, so gits solution may be fine too, but if i understand how it works, the cursors
          Message 4 of 8 , Jul 11, 2013
            thanks, i'll try the histadd() function first. i don't usually use marks, so gits' solution may be fine too, but if i understand how it works, the cursors jumps forward and then backward, and i suppose that would cause some flickering if the next match is out of the screen, wouldn't it?

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

            ---
            You received this message because you are subscribed to the Google Groups "vim_use" group.
            To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
            For more options, visit https://groups.google.com/groups/opt_out.
          • Matteo Cavalleri
            ok, just in case someone is interested, here s my solution. suggestions for improvements are welcome :) function! SuperStar() let w= ) .
            Message 5 of 8 , Jul 11, 2013
              ok, just in case someone is interested, here's my solution. suggestions for improvements are welcome :)

              function! SuperStar()
              let w='\<' . expand('<cword>') . '\>'
              call histadd('/', w)
              let @/=w
              endfunction
              nnoremap * :call SuperStar()<CR>:set hls<CR>

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

              ---
              You received this message because you are subscribed to the Google Groups "vim_use" group.
              To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
              For more options, visit https://groups.google.com/groups/opt_out.
            • Christian Brabandt
              ... Am I missing something, or is this the same as nnoremap * * (Well it doesn t highlight the match. But for that you can :set hls in your .vimrc if you
              Message 6 of 8 , Jul 11, 2013
                On Thu, July 11, 2013 17:52, Matteo Cavalleri wrote:
                > ok, just in case someone is interested, here's my solution. suggestions
                > for improvements are welcome :)
                >
                > function! SuperStar()
                > let w='\<' . expand('<cword>') . '\>'
                > call histadd('/', w)
                > let @/=w
                > endfunction
                > nnoremap * :call SuperStar()<CR>:set hls<CR>

                Am I missing something, or is this the same as
                nnoremap * *<c-o>

                (Well it doesn't highlight the match. But for that you can :set hls
                in your .vimrc if you like)

                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

                ---
                You received this message because you are subscribed to the Google Groups "vim_use" group.
                To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
                For more options, visit https://groups.google.com/groups/opt_out.
              • Matteo Cavalleri
                ... it s not really the same. your mapping makes the cursor jump forward and back, which may cause some flickering if the next match is outside of the
                Message 7 of 8 , Jul 11, 2013
                  Il giorno giovedì 11 luglio 2013 18:06:32 UTC+2, Christian Brabandt ha scritto:
                  >
                  >
                  > Am I missing something, or is this the same as
                  >
                  > nnoremap * *<c-o>
                  >

                  it's not really the same. your mapping makes the cursor jump forward and back, which may cause some flickering if the next match is outside of the currently displayed text. maybe not a big deal but if there's a better way to do it why not? :)


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

                  ---
                  You received this message because you are subscribed to the Google Groups "vim_use" group.
                  To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
                  For more options, visit https://groups.google.com/groups/opt_out.
                • Nikolay Pavlov
                  ... back, which may cause some flickering if the next match is outside of the currently displayed text. maybe not a big deal but if there s a better way to do
                  Message 8 of 8 , Jul 11, 2013


                    On Jul 11, 2013 11:29 PM, "Matteo Cavalleri" <cvlmtg@...> wrote:
                    >
                    > Il giorno giovedì 11 luglio 2013 18:06:32 UTC+2, Christian Brabandt ha scritto:
                    > >
                    > >
                    > > Am I missing something, or is this the same as
                    > >
                    > > nnoremap * *<c-o>
                    > >
                    >
                    > it's not really the same. your mapping makes the cursor jump forward and back, which may cause some flickering if the next match is outside of the currently displayed text. maybe not a big deal but if there's a better way to do it why not? :)

                    There is 'lazyredraw' to prevent flickering, but flickering is not a problem at all:

                        vim -u NONE -c 'nnoremap * *<C-o>' -c 'call setline(1, repeat([""], 100))' -c 'call setline("$", "abc")' -c 'call setline(5, "abc")' -c $'normal 4\C-e'

                    now press *: you will see "abc" jump from the top of the screen to the middle. This *is* the problem.

                    (Note: you need zsh for the $'' thing to work. Replace "\C-e" with what is appropriate for your shell.)

                    > --
                    > --
                    > 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
                    >
                    > ---
                    > You received this message because you are subscribed to the Google Groups "vim_use" group.
                    > To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
                    > For more options, visit https://groups.google.com/groups/opt_out.
                    >
                    >

                    --
                    --
                    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
                     
                    ---
                    You received this message because you are subscribed to the Google Groups "vim_use" group.
                    To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
                    For more options, visit https://groups.google.com/groups/opt_out.
                     
                     
                  Your message has been successfully submitted and would be delivered to recipients shortly.