Quantcast

Alt key mapping: "set <M-...>" works in Normal/Command mode, but not in Insert mode

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Alt key mapping: "set <M-...>" works in Normal/Command mode, but not in Insert mode

Jacky Liu
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Alt key mapping: "set <M-...>" works in Normal/Command mode, but not in Insert mode

Jacky Liu
My Vim version is 8.0.540 if it helps

--
--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Alt key mapping: "set <M-...>" works in Normal/Command mode, but not in Insert mode

Tony Mechelynck
On Wed, Apr 5, 2017 at 3:48 PM, Jacky Liu <[hidden email]> wrote:
> My Vim version is 8.0.540 if it helps

What does ":verbose set timeoutlen" answer?

I recommend someting like the following settings:

if exists('+timeout')
" should a timeout be applied to keys and mappings?
" 'timeout' true=yes false=no
" 'ttimeout' (not used if 'timeout' is true) time out on key codes
" 'timeoutlen' timeout duration on mappings
" 'ttimeoutlen': timeout duration on keycodes
"     (use 'timeoutlen') if negative)
" durations are in milliseconds
        set timeout timeoutlen=5000 ttimeoutlen=250
" ttimeoutlen should be longer than the hardware cycle but shorter
than your fastest typing speed
" timeoutlen should be longer than your slowest typing speed
endif

Best regards,
Tony.

--
--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Alt key mapping: "set <M-...>" works in Normal/Command mode, but not in Insert mode

Jacky Liu

>
> What does ":verbose set timeoutlen" answer?
>
> I recommend someting like the following settings:
>
> if exists('+timeout')
> " should a timeout be applied to keys and mappings?
> " 'timeout' true=yes false=no
> " 'ttimeout' (not used if 'timeout' is true) time out on key codes
> " 'timeoutlen' timeout duration on mappings
> " 'ttimeoutlen': timeout duration on keycodes
> "     (use 'timeoutlen') if negative)
> " durations are in milliseconds
>         set timeout timeoutlen=5000 ttimeoutlen=250
> " ttimeoutlen should be longer than the hardware cycle but shorter
> than your fastest typing speed
> " timeoutlen should be longer than your slowest typing speed
> endif
>
> Best regards,
> Tony.

Yes, the 'timeout' option is usable with my Vim, yet I'm afraid it doesn't help much here. For the Meta key mapping to work in Insert mode I have to do keymapping like this:

    inoremap <expr>   <Esc>j   InsertModeKeymapping('M-j')

And this will introduce ambiguity to the <Esc> key, Vim get stuck for a while to resolve it whenever the key was pressed under Insert mode. Also, from my understanding, the default status with 'timeout' not set equals 'timeoutlen' being set to infinite time, which is indifferent with, say, a large number.


--
--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Alt key mapping: "set <M-...>" works in Normal/Command mode, but not in Insert mode

Jacky Liu
In reply to this post by Tony Mechelynck
After a few tries I found something that looks a little bit strange to me: the Insert mode meta keymapping actually works, *only if* you set at least one mapping with the leading <Esc>.

Previously I tried my best to avoid mapping the <Esc> leading keys, although it works, because it would introduce ambiguity and get Vim stuck when <Esc> was pressed, but all the <M-...> mappings wouldn't work then, like they were all ignored.

Now I've found this:

    inoremap <Esc>m    <nop>

with this key mapping in place, suddenly, all my <M-..> mappings in Insert mode works!

But this mapping still introduces ambiguity to the Escape key, a dilemma ...




--
--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Loading...