Wednesday, April 5, 2017

Alt key mapping: "set " works in Normal/Command mode, but not in Insert mode

I am switching back to console Vim because it solved the No.1 problem of Gvim: it doesn't allow another thread to start a X based graphical UI, as it will clash with the one of its own. Also it now supports true color and is much faster in responding user ops.

Unfortunately I bumped into the old Alt key mapping problem. After examining all possibilities I think setting the key codes in Vim is the most practical:

function! s:ConsoleMapAltKey()
let char= 'a'
while char <= 'z'
exec "set <A-".char.">=\<Esc>".char
let char= nr2char(1+char2nr(char))
endwhile

set ttimeout
set ttimeoutlen=30
endfunction


This supposedly should tell Vim that the <Alt-...> key will generate <Esc> leading key sequences, and enable Vim to tell them apart from user input of <Esc> followed by other keys by the different time lapse.

This works perfectly under Normal and Command mode, no ambiguity when <Esc> was pressed, but not in Insert mode, where the <Alt-...> key combination will always be accepted as one <Esc> followed by another key from the user. I tried explicitly doing key mapping:

imap <A-s> xxx

and it didn't work. Can anyone enlighten me on this, thanks.



--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments: