2016-07-21 46 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