2016-07-21 42 views
1

我使用键绑定来添加/删除给定行中的注释。搜索并替换而不更改突出显示?

因为我不想Vim高亮所有评论开始后我使用它,键绑定包括与此

<CR>:nohlsearch<CR> 

的一个问题,就是它杀死所有的高亮显示。我真的很想做的事情是恢复到以前强调的任何事情。

这在Vim中可能吗?

+0

你能举个例子吗? – Sundeep

+2

您是否想过使用[commenting plugin](http://vimawesome.com/?q=comment),如[commentary.vim](https://github.com/tpope/vim-commentary)?支持良好的评论插件可以处理更多的文件类型,并且比大多数自主开发的解决方案更加强大。 –

回答

6
let old = @/  " preserve the old search 
%s/foo/bar/g  " search for foo and replace with bar 
let @/ = old  " stop highlighting "foo" and highlight whatever we did before