Is there an easy to remap alt key which is consistent with gvim on Windows and Linux?

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Is there an easy to remap alt key which is consistent with gvim on Windows and Linux?

Kevin Gao
Hello folks,

I would like to know: Is there an easy to remap alt key which is consistent with gvim on Windows and Linux?

On Windows/Linux,
inoremap <a-1> :echo "??? "<cr>
works.

But on MacVim, it does not work.

I check online: some one suggested this solution: https://stackoverflow.com/questions/7501092/can-i-map-alt-key-in-vim (1st solution).

The 1st solution is very bad to me, because it means I've to remap all alt keys, only for MacVim, which is very tedious.

So is there an easy to remap alt key which is consistent with gvim on Windows and Linux?

Thanks for your reply.

--
--
You received this message from the "vim_mac" 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_mac" 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
|

Re: Is there an easy to remap alt key which is consistent with gvim on Windows and Linux?

Tony Mechelynck
On Friday, December 21, 2018 at 12:52:16 AM UTC+1, Kevin Gao wrote:

> Hello folks,
>
> I would like to know: Is there an easy to remap alt key which is consistent with gvim on Windows and Linux?
>
> On Windows/Linux,
> inoremap <a-1> :echo "??? "<cr>
> works.
>
> But on MacVim, it does not work.
>
> I check online: some one suggested this solution: https://stackoverflow.com/questions/7501092/can-i-map-alt-key-in-vim (1st solution).
>
> The 1st solution is very bad to me, because it means I've to remap all alt keys, only for MacVim, which is very tedious.
>
> So is there an easy to remap alt key which is consistent with gvim on Windows and Linux?
>
> Thanks for your reply.
Some keys and key combinations are seen or not seen, or seen as different or as identical, different ways on different operating systems, indeed sometimes between gvim and Vim-in-Console on a single operating system.

The only way that I know of to use mappings consistently over all OSes, terminals and GUIs is to only use keys and key combinations which are seen, and seen as different, in all environments. This may require some trial and error but over the time I have come upon some rules of thumb:

- Printing keys are usually seen, and seen as different, everywhere, but most of those corresponding to an ASCII character, i.e. to something not higher than 0x7F, are already in use by Vim and should not be remapped. If your keyboard (and keyboard driver) can consistently produce printing keys above 0x7F (mine has §éèçಳù£µ plus quite a number of AltGr combinations) then those keys are candidates for remapping in Normal mode but maybe not in Insert mode.
- F keys are usually seen. Shift-F keys are usually seen in gvim but might be confused with the corresponding unshifted F keys when running in a terminal. Of these, F1 is usually reserved for Help and F10 is often reserved for Menu. Ctrl-F keys are usually preempted on Linux by the X11 window manager and thus usually won't reach Vim or gvim on Linux, so they should be avoided if compatibility with Linux is important to you.
- Cursor keys are usually seen, but they have so useful default bindings that IMHO they should not be remapped.
- Alt+printable keys are often seen as no different than the same key with no Alt but with the keycode ORed with 0x80. Alt+non-printable keys may or may not be seen, and if seen they might be seen as the same combo with fewer modifiers.

Best regards,
Tony.

--
--
You received this message from the "vim_mac" 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_mac" 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
|

Re: Is there an easy to remap alt key which is consistent with gvim on Windows and Linux?

Yee Cheng Chin-2
Kevin, are you using MacVim GUI or Terminal?

Terminal:
This is really implementation specific, but your best bet (if you are using Apple Terminal) is to enable the "Use Option as Meta Key" option, and then set the meta keys to the escape sequences similar to how Linux terminals work.

MacVim GUI:
Add this to your vimrc: "set macmeta". It will allow mapping <M-j> etc work, similar to gvim.

Just some additional notes about macmeta. It has a couple caveats:
* You can't use the macOS specific Meta key combos to enter special text. For example, in normal Mac applications, Cmd-; will enter "…", but if you turn on macmeta, it will enter "»" instead which is similar to how GVim works in other platforms.
* There are times where accented characters like å will interferer with your mappings. For example, typing å in MacVim with macmeta on is the same as typing Alt-e. See https://github.com/macvim-dev/macvim/issues/768 for more info.

One of the things on my list to look into is to make Meta / Ctrl mappings always work in MacVim. Vim GUIs tend to be a facade where they really pretend to be a terminal under-the-hood. In particular, it pretends to be a terminal with "8-bit" escape sequences (see ":help xterm-8bit"), which I think is kind of a relic of the terminal nature of Vim. The GUI has more information than a terminal app and can afford to treat meta key sequences separately from normal unicode characters. To properly fix it probably requires some fix in how Vim handles key input though (unless MacVim unilaterally makes such a change).

On Thu, Dec 20, 2018 at 4:15 PM Tony Mechelynck <[hidden email]> wrote:
On Friday, December 21, 2018 at 12:52:16 AM UTC+1, Kevin Gao wrote:
> Hello folks,
>
> I would like to know: Is there an easy to remap alt key which is consistent with gvim on Windows and Linux?
>
> On Windows/Linux,
> inoremap <a-1> :echo "??? "<cr>
> works.
>
> But on MacVim, it does not work.
>
> I check online: some one suggested this solution: https://stackoverflow.com/questions/7501092/can-i-map-alt-key-in-vim (1st solution).
>
> The 1st solution is very bad to me, because it means I've to remap all alt keys, only for MacVim, which is very tedious.
>
> So is there an easy to remap alt key which is consistent with gvim on Windows and Linux?
>
> Thanks for your reply.

Some keys and key combinations are seen or not seen, or seen as different or as identical, different ways on different operating systems, indeed sometimes between gvim and Vim-in-Console on a single operating system.

The only way that I know of to use mappings consistently over all OSes, terminals and GUIs is to only use keys and key combinations which are seen, and seen as different, in all environments. This may require some trial and error but over the time I have come upon some rules of thumb:

- Printing keys are usually seen, and seen as different, everywhere, but most of those corresponding to an ASCII character, i.e. to something not higher than 0x7F, are already in use by Vim and should not be remapped. If your keyboard (and keyboard driver) can consistently produce printing keys above 0x7F (mine has §éèçಳù£µ plus quite a number of AltGr combinations) then those keys are candidates for remapping in Normal mode but maybe not in Insert mode.
- F keys are usually seen. Shift-F keys are usually seen in gvim but might be confused with the corresponding unshifted F keys when running in a terminal. Of these, F1 is usually reserved for Help and F10 is often reserved for Menu. Ctrl-F keys are usually preempted on Linux by the X11 window manager and thus usually won't reach Vim or gvim on Linux, so they should be avoided if compatibility with Linux is important to you.
- Cursor keys are usually seen, but they have so useful default bindings that IMHO they should not be remapped.
- Alt+printable keys are often seen as no different than the same key with no Alt but with the keycode ORed with 0x80. Alt+non-printable keys may or may not be seen, and if seen they might be seen as the same combo with fewer modifiers.

Best regards,
Tony.

--
--
You received this message from the "vim_mac" 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_mac" 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.

--
--
You received this message from the "vim_mac" 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_mac" 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
|

Re: Is there an easy to remap alt key which is consistent with gvim on Windows and Linux?

Kevin Gao
In reply to this post by Tony Mechelynck
Some one just suggested me "set macmeta" should work. Thanks for the reply, anyway.

--
--
You received this message from the "vim_mac" 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_mac" 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
|

Re: Is there an easy to remap alt key which is consistent with gvim on Windows and Linux?

Kevin Gao
In reply to this post by Yee Cheng Chin-2
On Thursday, December 20, 2018 at 11:23:07 PM UTC-8, Yee Cheng Chin wrote:

> Kevin, are you using MacVim GUI or Terminal?
>
>
> Terminal:
> This is really implementation specific, but your best bet (if you are using Apple Terminal) is to enable the "Use Option as Meta Key" option, and then set the meta keys to the escape sequences similar to how Linux terminals work.
>
>
> MacVim GUI:
> Add this to your vimrc: "set macmeta". It will allow mapping <M-j> etc work, similar to gvim.
>
>
> Just some additional notes about macmeta. It has a couple caveats:
> * You can't use the macOS specific Meta key combos to enter special text. For example, in normal Mac applications, Cmd-; will enter "…", but if you turn on macmeta, it will enter "»" instead which is similar to how GVim works in other platforms.
> * There are times where accented characters like å will interferer with your mappings. For example, typing å in MacVim with macmeta on is the same as typing Alt-e. See https://github.com/macvim-dev/macvim/issues/768 for more info.
>
>
> One of the things on my list to look into is to make Meta / Ctrl mappings always work in MacVim. Vim GUIs tend to be a facade where they really pretend to be a terminal under-the-hood. In particular, it pretends to be a terminal with "8-bit" escape sequences (see ":help xterm-8bit"), which I think is kind of a relic of the terminal nature of Vim. The GUI has more information than a terminal app and can afford to treat meta key sequences separately from normal unicode characters. To properly fix it probably requires some fix in how Vim handles key input though (unless MacVim unilaterally makes such a change).
>
>
> On Thu, Dec 20, 2018 at 4:15 PM Tony Mechelynck <[hidden email]> wrote:
> On Friday, December 21, 2018 at 12:52:16 AM UTC+1, Kevin Gao wrote:
>
> > Hello folks,
>
> >
>
> > I would like to know: Is there an easy to remap alt key which is consistent with gvim on Windows and Linux?
>
> >
>
> > On Windows/Linux,
>
> > inoremap <a-1> :echo "??? "<cr>
>
> > works.
>
> >
>
> > But on MacVim, it does not work.
>
> >
>
> > I check online: some one suggested this solution: https://stackoverflow.com/questions/7501092/can-i-map-alt-key-in-vim (1st solution).
>
> >
>
> > The 1st solution is very bad to me, because it means I've to remap all alt keys, only for MacVim, which is very tedious.
>
> >
>
> > So is there an easy to remap alt key which is consistent with gvim on Windows and Linux?
>
> >
>
> > Thanks for your reply.
>
>
>
> Some keys and key combinations are seen or not seen, or seen as different or as identical, different ways on different operating systems, indeed sometimes between gvim and Vim-in-Console on a single operating system.
>
>
>
> The only way that I know of to use mappings consistently over all OSes, terminals and GUIs is to only use keys and key combinations which are seen, and seen as different, in all environments. This may require some trial and error but over the time I have come upon some rules of thumb:
>
>
>
> - Printing keys are usually seen, and seen as different, everywhere, but most of those corresponding to an ASCII character, i.e. to something not higher than 0x7F, are already in use by Vim and should not be remapped. If your keyboard (and keyboard driver) can consistently produce printing keys above 0x7F (mine has §éèçಳù£µ plus quite a number of AltGr combinations) then those keys are candidates for remapping in Normal mode but maybe not in Insert mode.
>
> - F keys are usually seen. Shift-F keys are usually seen in gvim but might be confused with the corresponding unshifted F keys when running in a terminal. Of these, F1 is usually reserved for Help and F10 is often reserved for Menu. Ctrl-F keys are usually preempted on Linux by the X11 window manager and thus usually won't reach Vim or gvim on Linux, so they should be avoided if compatibility with Linux is important to you.
>
> - Cursor keys are usually seen, but they have so useful default bindings that IMHO they should not be remapped.
>
> - Alt+printable keys are often seen as no different than the same key with no Alt but with the keycode ORed with 0x80. Alt+non-printable keys may or may not be seen, and if seen they might be seen as the same combo with fewer modifiers.
>
>
>
> Best regards,
>
> Tony.
>
>
>
> --
>
> --
>
> You received this message from the "vim_mac" 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_mac" 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.
Thanks.

I was asking about GUI. I reduced .vimrc to

set macmeta
nnoremap <m-1> :echo "aaa"<cr>
nnoremap <m-a> :echo "bbb"<cr>

However, it does not work. Any suggestion?

--
--
You received this message from the "vim_mac" 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_mac" 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
|

Re: Is there an easy to remap alt key which is consistent with gvim on Windows and Linux?

Kevin Gao
In reply to this post by Yee Cheng Chin-2
On Thursday, December 20, 2018 at 11:23:07 PM UTC-8, Yee Cheng Chin wrote:

> Kevin, are you using MacVim GUI or Terminal?
>
>
> Terminal:
> This is really implementation specific, but your best bet (if you are using Apple Terminal) is to enable the "Use Option as Meta Key" option, and then set the meta keys to the escape sequences similar to how Linux terminals work.
>
>
> MacVim GUI:
> Add this to your vimrc: "set macmeta". It will allow mapping <M-j> etc work, similar to gvim.
>
>
> Just some additional notes about macmeta. It has a couple caveats:
> * You can't use the macOS specific Meta key combos to enter special text. For example, in normal Mac applications, Cmd-; will enter "…", but if you turn on macmeta, it will enter "»" instead which is similar to how GVim works in other platforms.
> * There are times where accented characters like å will interferer with your mappings. For example, typing å in MacVim with macmeta on is the same as typing Alt-e. See https://github.com/macvim-dev/macvim/issues/768 for more info.
>
>
> One of the things on my list to look into is to make Meta / Ctrl mappings always work in MacVim. Vim GUIs tend to be a facade where they really pretend to be a terminal under-the-hood. In particular, it pretends to be a terminal with "8-bit" escape sequences (see ":help xterm-8bit"), which I think is kind of a relic of the terminal nature of Vim. The GUI has more information than a terminal app and can afford to treat meta key sequences separately from normal unicode characters. To properly fix it probably requires some fix in how Vim handles key input though (unless MacVim unilaterally makes such a change).
>
>
> On Thu, Dec 20, 2018 at 4:15 PM Tony Mechelynck <[hidden email]> wrote:
> On Friday, December 21, 2018 at 12:52:16 AM UTC+1, Kevin Gao wrote:
>
> > Hello folks,
>
> >
>
> > I would like to know: Is there an easy to remap alt key which is consistent with gvim on Windows and Linux?
>
> >
>
> > On Windows/Linux,
>
> > inoremap <a-1> :echo "??? "<cr>
>
> > works.
>
> >
>
> > But on MacVim, it does not work.
>
> >
>
> > I check online: some one suggested this solution: https://stackoverflow.com/questions/7501092/can-i-map-alt-key-in-vim (1st solution).
>
> >
>
> > The 1st solution is very bad to me, because it means I've to remap all alt keys, only for MacVim, which is very tedious.
>
> >
>
> > So is there an easy to remap alt key which is consistent with gvim on Windows and Linux?
>
> >
>
> > Thanks for your reply.
>
>
>
> Some keys and key combinations are seen or not seen, or seen as different or as identical, different ways on different operating systems, indeed sometimes between gvim and Vim-in-Console on a single operating system.
>
>
>
> The only way that I know of to use mappings consistently over all OSes, terminals and GUIs is to only use keys and key combinations which are seen, and seen as different, in all environments. This may require some trial and error but over the time I have come upon some rules of thumb:
>
>
>
> - Printing keys are usually seen, and seen as different, everywhere, but most of those corresponding to an ASCII character, i.e. to something not higher than 0x7F, are already in use by Vim and should not be remapped. If your keyboard (and keyboard driver) can consistently produce printing keys above 0x7F (mine has §éèçಳù£µ plus quite a number of AltGr combinations) then those keys are candidates for remapping in Normal mode but maybe not in Insert mode.
>
> - F keys are usually seen. Shift-F keys are usually seen in gvim but might be confused with the corresponding unshifted F keys when running in a terminal. Of these, F1 is usually reserved for Help and F10 is often reserved for Menu. Ctrl-F keys are usually preempted on Linux by the X11 window manager and thus usually won't reach Vim or gvim on Linux, so they should be avoided if compatibility with Linux is important to you.
>
> - Cursor keys are usually seen, but they have so useful default bindings that IMHO they should not be remapped.
>
> - Alt+printable keys are often seen as no different than the same key with no Alt but with the keycode ORed with 0x80. Alt+non-printable keys may or may not be seen, and if seen they might be seen as the same combo with fewer modifiers.
>
>
>
> Best regards,
>
> Tony.
>
>
>
> --
>
> --
>
> You received this message from the "vim_mac" 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_mac" 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.
Yes, it working. Thanks for letting me know.

Yes, please "make Meta / Ctrl mappings always work in MacVim", which is also important.

Thanks for your work.

--
--
You received this message from the "vim_mac" 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_mac" 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
|

Re: Is there an easy to remap alt key which is consistent with gvim on Windows and Linux?

Kevin Gao
I was asking about GUI, BTW. Thanks.

--
--
You received this message from the "vim_mac" 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_mac" 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.