Mapping: nohlsearch to exit key

I like to use hlsearch , but I don’t want everything to be highlighted after the search to solve this problem, I could just use :nohlsearch or the abbreviation, but it still requires a lot of effort, so I decided to try that when clicking escape. I came up with the following:

 nnoremap <ESC> :nohlsearch<CR> 

This works exactly the way I want in GVim, which I usually use for development, but it does not work in vim.

If I'm looking for something in vim, press escape to turn off the selection and use one of the arrow keys to go. Vim goes directly to insert mode and inserts the character in a new line.

Since I have never come across 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 full vim configuration here .

+6
vim
source share
2 answers

Your problem is that when you press <Up> , the terminal sends something like <Esc>OA (you will see it if you type <Cv><Up> in insert mode), which redirects to :nohlsearch<CR>OA I do not know any solution, except that I do not match one <Esc> , try either converting to double <Esc> .

+6
source share

is :noh still too much work?

EDIT : I don’t know about you, but I personally think: noh is easier than pressing the Esc key, since I can press all the buttons without stretching my little finger too far (which is why I think the default display is Esc to return to Command mode from Insert mode is a bit unsuccessful). If you really use so much: nohlsearch, you should probably reassign it to what you can reach from the Home Area (for example, regular letters or numbers, or maybe Ctrl letters).

Anyway, entering the exact command you give works in my vim (on gnome-terminal). Are you sure you will put the rule in the .vimrc file and not in the .gvimrc? Unlucky after restarting vim? Try :source /path/to/config/file and make sure this makes it work.

-3
source share

All Articles