Why does the star command, *, advance to the next match, rather than to the beginning of the current match (the word under the cursor when star is invoked)?
So often do I immediately back up (using N) to the word my cursor was over when I invoked the star command that I wonder if I can make this the default behavior. Is it possible? Is it misguided to want this?
I briefly grepped the vim source tree but was unable to find if anything for this exists.
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
Why would you want this? When I use * I want to find other usages of the word under the cursor. If it's about highlighting then you can easily add nnoremap * *N to your personal config.
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
I want it for example for doing a search and replace in a visually selected range of lines where the I make the selection by using *, V, and N.
For example, typing something like *VNN:s/C-R//replacement. If my cursor is over the word I want to replace, let's call it oldword, I can type * to select oldword as the search term, V to start a visual highlight, NN to select the range of lines that include two more instances of the search term, and type : to go into command mode (which prepopulates :'<,'>), and then do a search and replace by starting with s/, then typing CTRL-R / to paste \<oldword\>, and then complete the command :'<,'>s/\<oldword\>/newword/g.
Usually I want to replace the instance of oldword that my cursor was on when I typed *. So I type * and then immediately back up using N.
Why would you want the current behavior?
Thank you for the nnoremap suggestion. I'll try it.
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
How about these mappings:
# bounded search
nnoremap c* <Cmd>call expand('<cword>')->printf('\<%s\>')->setreg('/')<CR>cgn
# UNbounded search
nnoremap cg* <Cmd>call expand('<cword>')->setreg('/')<CR>cgn
Then:
c* (or cg*) while on the word you want to changeEscape to get back to normal mode. as many times as necessary to replace the next occurrences of the old word—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
Wow, nice! I'll play with that.
I'll close this issue, though I would still like to know what the motivation is for star to automatically advance to the next match.
I presume it's to make some repeated use nicer, but I just can't think of an example to demonstrate why.
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
Closed #11050 as completed.
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
@jzinn as I said, I use it (and I assume this is the original purpose) to find other usages of the word under the cursor. So I'm not interested in staying on the original match, I want to skip to other parts of the document where that word is used. For replacing the word, I use variations on the mappings @lacygoill suggested.
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
If i use the * family of commands, I always want the cursor move to the next/previous instance of the match.
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()