Reputation: 2637
I often use search and replace commands using / in vim scripts and user commands. One anoying side effect is that the search appears in the search command history when typing / followed by cursor-up. Can I prevent vim to enter the searches within scripts into the history? Also: Is there a better way to remove highlighting after such a search within a script or user command than to search for a very unlikely expression like /I_DO_NOT_EXIST_IN_THIS_FILE?
Upvotes: 1
Views: 232
Reputation: 4660
I use F9 to turn off/on highlighting on the previous search:
" Highlight searches
set hlsearch
noremap <F9> :set hlsearch! hlsearch?<CR>
Upvotes: 2
Reputation: 161674
Type :noh
to cancel the highlighting.
Type :call search('I_DO_NOT_EXIST_IN_THIS_FILE')
to search without search-history.
You can also :call histdel('/', -1)
to delete latest entry in search history.
Upvotes: 4