How to map ALT key in .vimrc?

To see what your terminal is sending when you press a key, switch to insert mode, press Ctrl+V, then the key. Most keys with most terminals send an escape sequence where only the first character is a control character; Ctrl+V inserts the next character literally, so you get to insert the whole escape sequence that way.

Different terminals send different escape sequences for some key combinations. Many terminals send the same character (^O) for both Ctrl+O and Ctrl+Shift+O; if that's the case, Vim won't be able to distinguish between them.

You mention that you're using Cygwin; which terminal you're running Vim in is the most pertinent information. If you're using the native Windows console, get yourself a better terminal. I recommend MinTTY for running Cygwin text mode applications in a terminal in Windows outside X, but Cygwin's Windows-native RXVT and PuTTYcyg are also good. (Also Console2 to run Windows console applications, but that's squarely off-topic here).


If Control+V followed by ALT-x shows ^[x (type in terminal) you can fix it with this small script from vim.wikia.com:

for i in range(97,122)
  let c = nr2char(i)
  exec "map \e".c." <M-".c.">"
  exec "map! \e".c." <M-".c.">"
endfor

Add to .vimrc for all alt key mappings.