tags:

views:

63

answers:

2

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.

A: 

is :noh still too much work?

EDIT: I don't know about you, but I personally think :noh is easier than pressing Esc key, since I can press all the buttons without stretching my pinky too far (which is why I think the default mapping of Esc for going back to Command Mode from Insert Mode is a bit unfortunate). If you really use the :nohlsearch that much, you probably should remap it to something you can reach from the Home Area (i.e. regular letters, or numbers, or perhaps Ctrl-letters).

Anyway, typing the exact command you give works in my vim (on gnome-terminal). Are you sure you put the rule in .vimrc file, instead of .gvimrc? No luck after restarting vim? Try :source /path/to/config/file and see if that makes it to work.

Lie Ryan
"or an abbreviation". `:noh` takes four letters my preferred solution only one. That may sound a little bit stupid to some people but I search often enough for things that this matters to me.
DasIch
I have escape ond caps lock because indeed the time required to reach the escape key is far too long.
DasIch
@Daslch: likewise, that's why we choose vim.
Lie Ryan
A: 

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>.

ZyX
Thanks for the explanation, I checked what the terminal sends and used that to solve the problem by mapping those.
DasIch