Background
It's nice to be able to type *
in normal mode and automatically have Vim search for the word under the cursor.
Question
Is there an analogous command for executing a find/replace?
E.g. the cursor is on "the" and the result is :%s/\<the\>/
so that I can easily type the only/g
for the full find/replace command :%s/\<the\>/the only/g
.
Update/clarification
I have learned from a comment on this question that a solution might involve, to quote that comment,
<C-r><C-w>
and<C-r><C-a>
on the:
command-line to insert the word (respectively the WORD) under the cursor.
This certainly works and could be used to write a custom command to do what I am asking (e.g., nnoremap ** :%s/<c-r><c-w>
).
Is that the best way to do this? Or is there a native Vim command that already does what I am looking for?
:nnoremap <leader>s :%s/\<<C-r><C-w>\>/
) (or alternatively,<C-r><C-a>
to useWORD
)*
) and then do your replace without search pattern:%s//the only/g
it will default to the previous search.