0

I usually press alt + , to insert <, it works fine in my zsh terminal and on every other application, but unfortunatly not on vim or neovim. I tried following but nothing worked:

map <M-,> "<"
map <M-,>='<'

I appreciate any help

vimscape
  • 11
  • 2
  • This question would be better suited for the Super User or Unix & Linux Stack Exchange sites, since it is not about code. – Aaron Meese Aug 22 '22 at 00:24
  • How is this not related to code? It is vim script. Unless you think vim script is not code, and whatever language you think is code is considered code. Do not make judgement too soon if you do not understand something. Is lua code, because lua can be used to configure neovim? – jdhao Aug 22 '22 at 02:22

1 Answers1

1

Everything is wrong, here.

First, you can't expect any of those mappings to do anything in insert mode because the :map command creates mappings for normal, visual, and operator-pending modes, not for insert mode. The first thing to change is thus to use the proper :map variant:

imap <M-,> "<"
imap <M-,>='<'

Second, the left-hand side of a mapping (the keys you want to press) and the right-hand side (what you want Vim to press instead) are supposed to be separated by whitespace so your second example wouldn't produce a mapping to begin with. It asks Vim to list insert mode mappings that contain <M-,>='<', which is pointless.

Third, the right-hand side of a mapping is a macro, where every character is used as if you typed it. "<" would literally insert a double quote, an angle bracket, and a double quote. If you want the mapping to insert a <, use a <:

imap <M-,> <

Fourth, I've heard that Neovim handles the Meta/Alt key better than Vim so the mapping above is still likely to be problematic in Vim, depending on the OS or the keyboard layout. For example, in Vim on macOS with the AZERTY layout, the system translates Alt+, to before it even reaches Vim so <M- and <A- mappings simply don't work reliably.

romainl
  • 186,200
  • 21
  • 280
  • 313