Reputation: 2589
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.
Upvotes: 9
Views: 7077
Reputation: 163
I created this map to disable search when press double <Esc>
nnoremap <silent> <Esc><Esc> :let @/ = ""<CR>
Upvotes: 0
Reputation: 53604
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>
.
Upvotes: 8
Reputation: 64837
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.
Upvotes: -5