Thursday, December 15, 2016

Re: How to prevent asterisk key from advancing to next match when pressed

On Wed, Dec 14, 2016 at 4:03 AM, Slartibartfast
<his.royal.slartness@gmail.com> wrote:
> I frequently use the asterisk key (*) in conjunction with 'hlsearch' to highlight all occurrences of a word in a file. Normally when I do this I don't actually want to advance to the next match so I use 'nnoremap' to automatically wind back to the occurrence I was on when I pressed the key, as in:
> :set nnoremap * *N
>
> For the most part this works fine, however if the next occurrence of a match is off the screen the 'N' command does indeed bring you back to the correct place but that line is then placed at the top of the screen. One can of course remap to "*Nzz" to then bring that line to the center of the screen but that's a bit of a kludge as well.
>
> Anyone know a way to achieve setting the search word like this without causing the screen to be scrolled? I'm sure it must be possible but I'm having trouble working it out myself.
>
> Thanks.
>

The following mapping searches for a string on a double click.

nnoremap <silent> <2-LeftMouse> :let @/='\V'.escape(expand('<cword>'),
'\').''<cr>:set hls<cr>

It also does not add that word to the search history. For example if
you use the above mapping and double click on word "foo". It will
highlight all occurrences of foo in the file. But if you do /<UP>, it
will not list foo.

I find the above mapping very helpful when reading a piece of code and
want to see all the occurrences of a variable name.

hope that helps
raju
--
Kamaraju S Kusumanchi | http://raju.shoutwiki.com/wiki/Blog

--
--
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@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments: