让我们看一个简单的例子:
Some text TOM, some text
^ (my cursor here)
Some TOM, some text
Run Code Online (Sandbox Code Playgroud)
按下后*我得到:
Some text TOM, some text
Some TOM, some text
^ (now cursor here)
Run Code Online (Sandbox Code Playgroud)
它总是跳到下一个单词,这很烦人.我只是希望它保持在相同的位置,包括TOM搜索模式(下一次出现按下n).当我想从光标开始重构变量名时,它很有用.
例如,如果*只是在搜索模式中包含一个单词,我可以执行以下操作:
tom := "some text"
^ (cursor)
func test() {
println(tom)
}
Run Code Online (Sandbox Code Playgroud)
*(将旧名称添加到模式中)ciw(更改单词)newname(编写新单词)n(下次出现).(重复上一个命令).有没有改变行为的选择?
你只需要``(2个反引号,加里伯恩哈特称之为"滴答滴答")跳回:
*``ciwfoo<Esc>n.n.
Run Code Online (Sandbox Code Playgroud)
请注意,您可以使用cgn而不是ciw跳过n步骤:
*``cgnfoo<Esc>..
Run Code Online (Sandbox Code Playgroud)
如果您不想按"勾选回拨",则重新映射:
nnoremap <key> *``cgn
nnoremap <other-key> #``cgN
Run Code Online (Sandbox Code Playgroud)