Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mapping :nohlsearch to escape key

Tags:

vim

I like to use hlsearch but I hate to keep everything highlighted after searching, to solve this problem I could simply use :nohlsearch or an abbreviation of it but that is still to much effort so I decided to try to do that on pressing escape. What I came up with is:

nnoremap <ESC> :nohlsearch<CR>

This works exactly as I want it to in GVim which I usually use for development but it does not work in vim.

If I search something in vim, press escape to deactivate the highlighting and use one of the arrow keys to navigate vim goes directly into insert mode and inserts a character on a new line.

As I never really came around to using h, j, k and l for navigation this is really annoying and I would like to know how I can make vim behave like gvim.

If you need more information you can find my entire vim configuration here.

like image 695
DasIch Avatar asked Sep 11 '10 13:09

DasIch


Video Answer


1 Answers

Your problem is that when you press <Up> terminal sends something like <Esc>OA (you will see it if you type <C-v><Up> in insert mode) which is remapped to :nohlsearch<CR>OA. I do not know any solution except not mapping a single <Esc>, try either mapping to double <Esc>.

like image 133
ZyX Avatar answered Sep 24 '22 15:09

ZyX