β’0Guhn
Vim cgn + . Multiple Replace
#vim#neovim#cgn
Principle
| Key | Action |
|---|---|
c |
change - delete and enter Insert mode |
gn |
select next search match (Visual) |
. |
repeat last change |
cgn = delete next search match + Insert mode
Basic Usage
Replace word at cursor
* " search word under cursor
cgnnewword<Esc> " replace
. " replace next match
. " repeatSearch and replace specific word
/target<CR> " search
cgnnewword<Esc> " replace
. " repeatReplace with copied word
/oldWord<CR> " search word to replace
yiw " copy replacement word
cgn<C-r>0<Esc> " replace with register 0 content
. " repeat| Key | Action |
|---|---|
yiw |
copy word at cursor (register 0) |
<C-r>0 |
paste register 0 in Insert mode |
Cheatsheet
| Situation | Command |
|---|---|
| Replace cursor word | * β cgnnewword<Esc> β . |
| Search and replace | /search<CR> β cgnnewword<Esc> β . |
| Replace with copied word | /search<CR> β yiw β cgn<C-r>0<Esc> β . |
| Skip | n |
| Previous match | N |
gn vs n
n: move onlygn: select (Visual)
c deletes selected region, so gn is needed.
Turn off highlight
:nohKeybinding:
nnoremap <leader>h :nohlsearch<CR>Log
- β’ 2026-02-03: create