In vim, I've got the hlsearch
and incsearch
options turned on. When I start a search, it immediately goes to the first match. If I press Enter to accept the search, the result is highlighted and the cursor is positioned at the first match. If I press Esc to cancel, the cursor position is reset to wherever I was when I started the search.
Is there a way in this case to make Esc cancel the search but leave the cursor position on the first match? That way I'd end up in the right spot but without anything highlighted.
Thanks!
<c-l>
which redraws the screen to also clear highlighting:nnoremap <silent> <C-l> :noh<CR><C-l>
. If your terminal can handle it mapping<esc>
is also nice:nnoremap <silent> <esc> <esc>:noh<cr>
– Tap