Closed zzJinux closed 2 years ago
This isn't a new issue. I can replicate the behavior pre 173. OS: 11.6.8, intel Macbook pro 2019.
That's just how Vim works in general. You also get the same thing with Ctrl modifiers for example. What MacVim does is to make a new modifier <D-
to allow mapping of Cmd keys but the core Vim logic is the same.
Actually let met think about this a little more.
I agree with @ychin. Vim core for each mode has its own mapping table. For keys not listed in the table it print out keys in insert mode.
@eirnym @ychin I'm having trouble finding how to disable this behavior. Would you mind if you let me know? Thank you.
I remember this behavior in vim since forever (not only since I'm using MacVim). I'd suggest to ask in https://github.com/vim/vim or in stack overflow community.
@eirnym MacVim.app and vim --clean
from Terminal.app shows different result:
INSERT mode | mvim --clean | vim --clean (Terminal.app) | vim --clean (Terminal.app, delete F8-related keymaps) |
---|---|---|---|
⌘K | Inserts <D-k> |
Terminal.app clears the screen | (same as the left) |
⌘Y | Inserts <D-y> |
Nothing happens (bell) | (same) |
⌘[ | Inserts <D-[> |
Nothing happens (bell) | (same) |
⌘ F8 | Inserts <D-F8> |
Inserts <F8> |
Nothing happens (bell) |
⇧⌘ F8 | Inserts <S-D-F8> |
Nothing happens (bell) | (same as the left) |
⌃⇧⌘ F8 | Inserts <C-S-D-F8> |
Nothing happens (bell) | (same) |
⌥⌃⇧⌘ F8 | Inserts <M-C-S-D-F8> |
Nothing happens (bell) | (same) |
vim
is from the MacVim.app
contents.
To me, it is more of MacVim's issue.
I meant that Vim inserts unmapped sequence to the input directly.
Also Vim interprets keys differently when they come via terminal and GUI. This is common for all GUIs
What exactly is mapped or not it's a different question and I understand that your issue is not about this topic.
https://github.com/vim/vim/issues/3036
It implies that there is no way to disable the behavior in question, except that I have to manually map every key combination, which happens to annoy me, to <NOP>
. This is so frustrating 😢.
Additionally, it's well known that Terminal.app
consumes all key combinations with Cmd in it( (or cmd itself in some cases). Thus if you want to use these combinations in terminal, I suggest use alternative terminal like Kitty or iTerm. As far as I know they send combinations with cmd to an app
@eirnym Thank you! I have confirmed that iTerm.app
allows mapping Cmd key combinations while Terminal.app
does not; it has very limited options for key combinations (e.g. you can't use alphabet characters).
Back to the main topic, it seems reasonable that this issue be closed 😢.... or there may be other solution?
You're welcome
So, terminals in general don't know anything about Cmd keys. There aren't standardized ways to send command key combos to Vim or other terminal programs, and Vim itself also doesn't know much about cmd keys. From digging around, Vim's support of the command key (MOD_MASK_CMD
) is more than a decade old and seems to be implemented for the old, now defunct, Carbon-based gVim on the Mac (in the now-deleted gui_mac.c
), and has special cases sprinkled all over. Since that UI is no longer used, only MacVim uses it.
There is some special code in edit.c
's insert_special()
function that forcefully prints out sequences like <D-j>
when you press Cmd-j. It's also really old code. We could potentially remove it so it doesn't do that, but I also kind of don't feel like doing it, and it's also better done upstream at Vim.
Is there a reason why this bothers you anyway @zzJinux ? Are you making a mistaken Cmd key press and seeing this all the time?
Speaking of which you said iTerm supports the cmd key, is that true @zzJinux ? It seems to have some support but I was struggling to map any <D-
keys to Vim and get it to work.
@ychin yes, iTerm supports passing through keys with Cmd key if they not already bonded with iTerm itself
Closing this issue. This feature has been like this for a while. It's not worth changing it now.
@ychin
This turned up to me when, while using Macvim (GUI), one app triggered a werid key combination. <M-C-S-D-F19>
is inserted everytime I hit CapsLock key. I have already sent an email to the developer of that app, not receiving any response yet. Subsequently I realized that some other key combinations showed the same behavior.
While using the terminal vim, almost all mistakten key combinations are effectively ignored due to the terminal application's default setting (I use Terminal.app
personally). It seems to be gvimrc
's responsibility to ignore those while using GUI MacVim.
MacVim may introduce another method in the future. For now, I will go with gvimrc
.
Hmm but I mean Terminal would not block it if you hit say <F-10>
and it will definitely print that. I’m not sure why it’s blocking the weird combo above but seems like the general issue here is that your tool is generating these key presses.
I kind of prefer not adding MacVim specific changes here and I don’t think think it’s MacVim’s job to block random Function keys just because some tool generates it. I can somewhat see doing something about the <D-
Cmd key stuff but seems like that’s not your issue anyway.
Maybe Vim can add an option to not print Function keys (or other unmapped special keys like cmd keys) if they are not mapped (unless in i_Ctrl-V
)? I think that’s the best solution I can think of. Feel free to file an issue there.
Steps to reproduce
I have reproduced the above with following conditions:
mvim --clean
Expected behaviour
Except for some predefined keymaps (Copy, Paste, ...), nothing happens.
Version of Vim and architecture
9.0.65 (173), GUI, arm64
Environment
Operating System: Monterey, arm64
How MacVim was installed
GitHub
Logs and stack traces
Vim configuration where issue is reproducable
No response
Issue has been tested with given configuration
Issue has been tested with no configuration
mvim --clean
(orgvim
, supplied by MacVim distribution)vim --clean
(in terminal, supplied by MacVim distribution)vim --clean
(in terminal, other suppliers, e.g. /usr/bin/vim)Other conditions