简体   繁体   中英

How do I map keys to assign a value in vim?

I am using highlighted search in vim. So when I search for a word, all occurrences of the word get highlighted. After I'm done, I want to remove the highlighting.
According to the Vim Documentation , :let @/="" clears the last searched pattern and removes the highlighting.

So I am trying to map Ctrl+/ to :let @/="" .

I've added the following line to my .vimrc

nnoremap <C-/> :let @/=""<CR>

But it doesn't work. Ctrl+/ doesn't clear the search patter. On the other hand, if I manually type in :let @/="" , it works fine.

What am I doing wrong?

I use this in my vimrc:

nnoremap <Esc> :noh<CR>

Mapping this to Esc seems natural to me.

Due to the way that the keyboard input is handled internally, this unfortunately isn't generally possible today, even in GVIM. Some key combinations, like Ctrl + non-alphabetic cannot be mapped, and Ctrl + letter vs. Ctrl + Shift + letter cannot be distinguished. (Unless your terminal sends a distinct termcap code for it, which most don't.) In insert or command-line mode, try typing the key combination. If nothing happens / is inserted, you cannot use that key combination. This also applies to <Tab> / <CI> , <CR> / <CM> / <Esc> / <C-[> etc. (Only exception is <BS> / <CH> .) This is a known pain point, and the subject of various discussions on vim_dev and the #vim IRC channel.

Some people (foremost Paul LeoNerd Evans) want to fix that (even for console Vim in terminals that support this), and have floated various proposals, cp. http://groups.google.com/group/vim_dev/browse_thread/thread/626e83fa4588b32a/bfbcb22f37a8a1f8

But as of today, no patches or volunteers have yet come forward, though many have expressed a desire to have this in a future Vim 8 major release.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM