Wednesday, December 14, 2016

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

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.

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