每天一个vim小技巧[3] - 搜索并替换当前光标处的字

1. search and replace word under current cursor

需求:使用全局替换而不必手动输入当前光标处的字

image

使用 vim inbuit key binding: <C-r><C-w>

:%s/<C-r><C-w>/{your_new_word}/g
# % takes the search globally.

2. search and replace in specified lines

需求:替换77到79行的122为245

image

:77,79 s/122/245/g
posted @ 2023-05-19 10:22  devindd  阅读(77)  评论(0编辑  收藏  举报