Make *
stay at the cursor position
nnoremap * m`:keepjumps normal! *``<cr>
https://stackoverflow.com/questions/4256697/vim-search-and-highlight-but-do-not-jump
There are quite a few (lightweight) plugins which try to enhance searching in vim with the star command.
Typically, people miss that the star command does not consider a visual selection and secondly, what you want, to not move the cursor when pressing *
.
After installation of one of these, you would press *cgn
to achieve what you want.
In case of vim-asterisk
, you have to override the builtin *
yourself in your vimrc. vim-asterisk
suggests:
map * <Plug>(asterisk-*)
map # <Plug>(asterisk-#)
map g* <Plug>(asterisk-g*)
map g# <Plug>(asterisk-g#)
map z* <Plug>(asterisk-z*)
map gz* <Plug>(asterisk-gz*)
map z# <Plug>(asterisk-z#)
map gz# <Plug>(asterisk-gz#)
where z*
means stay. However, you can make *
to stay with
map * <Plug>(asterisk-z*)
map # <Plug>(asterisk-z#)
map g* <Plug>(asterisk-gz*)
map g# <Plug>(asterisk-gz#)
vim-slash does this for you. This might be a reason to prefer vim-asterisk because you have control of what gets remapped.
There are more of them. Just to give you an idea I mention a few:
Plugin with new operator: sad.vim
If you like an explicit mapping for this operation, consider https://github.com/hauleth/sad.vim. This remaps s
(changes builtin and clashes with a few other plugins, e.g. vim-sneak and vim-sandwich). siw
and then press .
as often you want to repeat the change for the next search matches.