Re: Analog to SHIFT+Asterisk
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('cword>').'\>') 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 * 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 | / -- for why I used '' in the mapping :help : -- 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
RE: Analog to SHIFT+Asterisk
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
Re: Analog to SHIFT+Asterisk
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
Re: Analog to SHIFT+Asterisk
On Jun 30, 6:29 pm, Hoss 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
Re: Analog to SHIFT+Asterisk
On 2010-07-01, BC wrote: > On Jun 30, 6:29 pm, Hoss 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