在vim/gvim中,我希望能够移动到当前搜索查找的前端和末尾.这可能吗?
例如,使用此文件:
A dog and a cat
A hat and a bat
Run Code Online (Sandbox Code Playgroud)
我希望能够执行搜索,例如/dog\sand,然后能够从'dog and'表达式的开头移动到结束和返回,以便我的光标从第3列开始,在字母'd'下面单词'dog'然后移到第9列的字母'd'或单词'and'.
我希望能够这样做的原因是我可以搜索表达式然后使用更改命令c,并结合移动命令来替换该特定搜索表达式.我不想在这里使用substitue和替换,我想使用change命令和移动键来执行此操作.
Qui*_*ahl 38
你在找cgn.来自:help gn:
Search forward for the last used search pattern, like
with `n`, and start Visual mode to select the match.
If the cursor is on the match, visually selects it.
If an operator is pending, operates on the match.
E.g., "dgn" deletes the text of the next match.
If Visual mode is active, extends the selection
until the end of the next match.
Run Code Online (Sandbox Code Playgroud)
你可以这样做cgn,然后重复命令.,是的,它将在下一个搜索模式匹配上执行相同的操作.当您开始使用复杂的正则表达式进行搜索时,这将变得非常有用.
Aus*_*lor 17
您可以更改为匹配结束c//e<CR>.并//<CR>会带你到下一场比赛的开始.你可以为那些有意义的东西找出某种绑定.例如,我刚刚尝试了以下内容,它看起来效果很好:
:onoremap <silent>m //e<CR>
Run Code Online (Sandbox Code Playgroud)
所以你可以说cm改变匹配.不过,我不确定我会映射//<CR>到什么.我尝试将其映射到n,它似乎工作正常.不知道这对你来说是否有问题.
:nnoremap <silent>n //<CR>
Run Code Online (Sandbox Code Playgroud)
anu*_*ava 14
尝试:
/pattern<cr> to place the cursor at the start of search pattern
/pattern/e<cr> to place the cursor at the end of search pattern
Run Code Online (Sandbox Code Playgroud)