1

In my .vimrc I've enabled highlighting the searched text (which I find to be a handy feature and wouldn't want to disable it).

set hlsearch

And, following answers to this question, I've made a mapping to be able to clear the highlight:

nmap <silent> ,/ :nohlsearch<CR>

The problem comes with commands which include search. For example, delete to next character 'x':

d/x

This will automatically highlight all the instances of 'x'. To remove this highlight I have to punch ,/ to clear it, which is quite annoying.

The question. Is it possible to enforce :nohl if the search is a part of a preceding command? Maybe, it is possible at least for a selected list of commands (say, d, y and c) before / character is hit?

4

2 回答 2

0

如果“x”与光标在同一行,则可以使用 dtx(意思是删除到 x)。

于 2013-10-18T09:34:16.153 回答
0

d/x正如你所描述的那样对我不起作用。(我在这里使用vim 7.3,在正常模式下无法理解/以下内容d,因此忽略d并开始常规/搜索。)
如果您想删除到下一个x,那么dfx或者dtx是我会使用的(取决于您是否还想删除 x 本身)。
不涉及突出显示。
希望有帮助。

[在评论中进行了一些澄清。]
我认为应该可以编写一个自定义函数来执行您想要的操作,然后分配一个自定义键序列来调用该函数。
我玩了一点,但不是很精通 vim 功能,无法让它工作。
这是我尝试过的:

function! g:DeleteToSearchAndNohls(term)  
    :normal d/a:term  
    :nohlsearch  
endfunc  
于 2013-10-18T01:19:16.413 回答