1

Trying to map the NERDCommenter's toggle comment action (mapped to <leader>c<space>) to alt+/, something a bit more familiar. I tried:

nnoremap <A-/> <leader>c<space>

...but it doesn't seem to work or do anything. Do I have the key alt+/ wrong ? how can you represent the / character in .vim ?

B Layer
  • 19,834
  • 2
  • 30
  • 57
  • 1
    Does this answer your question? How to map Alt key? – B Layer Nov 20 '20 at 20:34
  • 1
    / is /. It's not the problem. Did you try Insert mode, hit Ctrl-V then hit Alt-/? Whatever you see there make that the mapped key. In one of my environments it's ^[/. The ^[ is the control character equivalent to Esc. So I do nnoremap <Esc>/ etc. That's an example. – B Layer Nov 20 '20 at 21:28
  • I just noticed you said "nvim" in your comment (but not in your question...you should specify that). See :h :map-alt-keys. (It says something similar to my last comment.) ..... (Edit: I added "nvim" tag to your question) – B Layer Nov 20 '20 at 21:40
  • Just tried it, it just doesn't read anything it seems, like nothing is sent through or vim is listening for the wrong key. Because literally no action takes place, I go to insert mode, press ctrl-o, and press alt+/ but nothing takes places, it just keeps waiting for a command.

    I tried: nnoremap ^[/ <leader>c<space> nnoremap <Esc>/ <leader>c<space> nnoremap <A-/> <leader>c<space>

    – 8c6b5df0d16ade6c Nov 21 '20 at 08:21
  • Ctrl-V not Ctrl-O – B Layer Nov 21 '20 at 11:21
  • I ended up configuring my terminal to output ^[* whenever I press alt+/ and configured nvim to listen for, the equivalent, <A-*>. Now it all works great. – 8c6b5df0d16ade6c Nov 22 '20 at 19:26
  • Glad you got things working to your liking but Alt-/ shouldn't be broken like that. What if you configure the terminal to output ^[/ ? (!) Beyond that problem could be misconfiguration of the terminal or Vim's terminal config. You can try the following to see whether the problem is isolated to Vim: from shell prompt cat > /tmp/foo, type Alt-/ then hit Enter, type Ctrl-D, then run cat -v /tmp/foo. Similar to the Ctrl-V test in Vim this will show you the actual characters emitted by Alt-/. See anything different doing it this way? – B Layer Nov 23 '20 at 07:10

0 Answers0