0

I am trying to remap the * operator in VIM. I have tried nnoremap <*> and nnoremap <S-8> to no avail. I haven't been able to find any instructions on how to properly do this. How can I remap my *, or any number keys/number key special characters?

Since many of you will no doubt wonder why anyone would want to do this, it's so I can make my * operator behave like normal, except not advance automatically to the next occurrence of the word under cursor (see under section Highlight Matches Without Moving).

EDIT:

The complete command I'm working with is this:

nnoremap <*> :let @/='\<<C-R>=expand("<cword>")<CR>\>'<CR>:set hls<CR>

Where * remaps the functionality of * or <shift + 8>

Community
  • 1
  • 1
Freedom_Ben
  • 11,247
  • 10
  • 69
  • 89

2 Answers2

1

Getting rid of the < and > works for me.

nnoremap * :let @/='\<<C-R>=expand("<cword>")<CR>\>'<CR>:set hls<CR>
Chris
  • 17,119
  • 5
  • 57
  • 60
  • 2
    @Freedom_Ben Check out `:h key-notation`. Everything not listed there needs to be used without surrounding `<…>`. Also note that vim uses byte queue to represent typed keys and is never receiving anything like `Shift` + `8`: never anything with modifiers. `` keys are one byte control characters resting between 0x01 and 0x1F in ASCII table, `` are `…` and things like `` are internal escape sequences starting with 0x80 byte (in terminal they are first received as something like `[11~`, but then transformed). `` is additionally `A`. You can always use this directly. – ZyX Apr 25 '13 at 04:25
  • @ZyX, thanks for the awesome explanation! That clarifies things greatly. If you want to post it as an additional answer, I'll vote it up. I think it would be really helpful to people visiting this question in the future as well. – Freedom_Ben Apr 25 '13 at 16:04
-1

Try nnoremap <F7> <*>. It will remap the * with F7

Hoan Dang
  • 2,222
  • 5
  • 27
  • 36
  • I tried your suggestion several ways and it didn't seem to work. Can you provide a more complete example? I've added my entire command to the question. – Freedom_Ben Apr 24 '13 at 17:58
  • This will remap `` with three symbols: `<`, `*` and `>`. – ZyX Apr 25 '13 at 04:18