[vim/vim] enable <D-*> mappings in GTK (PR #12698)

54 views
Skip to first unread message

Casey Tucker

unread,
Jul 23, 2023, 1:25:17 AM7/23/23
to vim/vim, Subscribed

Description

As a developer who works in both MacVim and gvim on Linux using the same keyboard, it can be frustrating having to remember different key combinations or having to rely on system utilities to remap keys.

This change allows <D-z> <D-x> <D-c> <D-v> etc. to be recognized by the map commands, along with the <D-S-...> shifted variants.

Example .vimrc

if has('gui_gtk')
	nnoremap  <D-z>    u
	nnoremap  <D-S-Z>  <C-r>
	vnoremap  <D-x>    "+d
	vnoremap  <D-c>    "+y
	cnoremap  <D-v>    <C-R>+
	inoremap  <D-v>    <C-o>"+gP
	nnoremap  <D-v>    "+P
	vnoremap  <D-v>    "-d"+P
	nnoremap  <D-s>    :w<CR>
	inoremap  <D-s>    <C-o>:w<CR>
	nnoremap  <D-w>    :q<CR>
	nnoremap  <D-q>    :qa<CR>
	nnoremap  <D-t>    :tabe<CR>
	nnoremap  <D-S-T>  :vs#<CR><C-w>T
	nnoremap  <D-a>    ggVG
	vnoremap  <D-a>    <ESC>ggVG
	inoremap  <D-a>    <ESC>ggVG
	nnoremap  <D-f>    /
	nnoremap  <D-g>    n
	nnoremap  <D-S-G>  N
	vnoremap  <D-x>    "+x
endif

You can view, comment on, or merge this pull request online at:

  https://github.com/vim/vim/pull/12698

Commit Summary

  • 192785e enable <D-*> mappings in GTK

File Changes

(7 files)

Patch Links:


Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/12698@github.com>

Tony Mechelynck

unread,
Jul 23, 2023, 2:03:51 AM7/23/23
to vim/vim, Subscribed

How woud you produce a <D- (Command) modifier on GTK (i.e. on Unix/Linux with X11)? There is no Command key other than on Mac.
If you want to use the same mappings everywhere, don't use Cmd- mappings but only Shift- Ctrl- and/or Alt- (i.e. Meta- ).
In my experience, using F1 to F12 with or without Shift, except unshifted F1 and F10, as {lhs} of a mapping, is a good idea because these keys have no default function in Vim.

Best regards,
Tony.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/12698/c1646755386@github.com>

Christian Brabandt

unread,
Jul 23, 2023, 6:18:05 AM7/23/23
to vim/vim, Subscribed

hm, can we have tests please? Can we make it a bit more explicit, that <D- is done using the <super> key on non-Macs?


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/12698/c1646801963@github.com>

Casey Tucker

unread,
Jul 23, 2023, 1:23:04 PM7/23/23
to vim/vim, Subscribed

Replying first to @tonymec:

How woud you produce a <D- (Command) modifier on GTK (i.e. on Unix/Linux with X11)?
There is no Command key other than on Mac.

My keyboard has two Command keys on it, and on my installed distro this key is mapped to Super. I'm pretty sure standard keyboards have Windows keys which behave similarly. I mentioned that the Super key is used for this in GTK in the documentation though I may have failed to make this clear in the commit message / PR description.

If you want to use the same mappings everywhere, don't use Cmd- mappings but only Shift- Ctrl- and/or Alt- (i.e. Meta- ).

I've been using vim for more than 20 years, MacVim for 15 years, and the GTK port for about 5 years. Shouldn't muscle memory be considered a valid reason to configure a particular binding?

I already have mappings on these modifiers. When I go to press Cmd-anything on the GTK port presently, it ignores that the Cmd key is pressed entirely. It's an awful experience when you expect Cmd+C to copy a visual selection to the global clipboard only for gvim to instead erase everything because it thought you meant 'C' for change, and equally frustrating when Cmd+V doesn't paste as expected. Already attempted remedies include using xmodmap, xbindkey, KDE's keyboard shortcut settings and those in GNOME (pre GTK).

In my experience, using F1 to F12 with or without Shift, except unshifted F1 and F10, as {lhs} of a mapping, is a good idea because these keys have no default function in Vim.

Others may have a different experience that is equally valid. My keyboard does not have dedicated F1-F12 keys; I access those through a mod layer. Not everyone uses the same hardware and people develop their own preferences, especially in an application such as vim where everything can be mapped. Accessibility is important and this pull request makes the GTK port more accessible by enabling another modifier.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/12698/c1646897055@github.com>

Casey Tucker

unread,
Jul 23, 2023, 1:33:39 PM7/23/23
to vim/vim, Subscribed

@chrisbra

hm, can we have tests please? Can we make it a bit more explicit, that <D- is done using the <super> key on non-Macs?

I may need a bit of advice on how to write a test for this. I imagine the main test case would be checking that <D- is recognized on Mac and GTK as a shortcut by the parser and is accepted as a binding by the map command. Would you be able to point me in the right direction with a link to documentation for test writing, or to an existing test that I could adapt towards this case? Are there additional test cases I should be considering?

I'd also appreciate suggestions on how to make this more explicit. I wasn't able to identify any other parts of the builtin documentation that mention this previously Mac-only functionality, so I just amended those sections to indicate that it's available on GTK. Please let me know what more is needed. I'm comfortable doing the technical writing if it's needed, I would just need to know what to write and where.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/12698/c1646899502@github.com>

Christian Brabandt

unread,
Jul 23, 2023, 2:32:39 PM7/23/23
to vim/vim, Subscribed

There are a few things that could be tested. What happens, when pressing i_CTRL-V followed by e.g. Super-M? Does Vim insert <D-M>? Then if you map a super-key, does it show up in the mapmode listing? And finally of course, does it do what it is supposed to be doing when mapping <D-..> and feeding this character as input to feedkeys() ? What about mapping to a multi-byte character? Does Vim get the right key under xterm (with modifyOtherKeys set to 2 (enabled) and 0 (disabled)) What about kitty protocol for the kitty terminal?

See test_mapping See e.g. Test_map_meta_quotes() and Test_map_meta_multibyte()

You may need to protect the test by testing for if has("gui_gtk") || has("gui_gtk3") || has("macos").

Regarding the Documentation, I guess this line should be adjusted as well. And perhaps add a section for the Super/Cmd-Key like this one here


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/12698/c1646925359@github.com>

Yegappan Lakshmanan

unread,
Jul 23, 2023, 4:28:08 PM7/23/23
to vim...@googlegroups.com, reply+ACY5DGEFK4WBITAW7C...@reply.github.com, vim/vim, Subscribed
Hi,

On Sun, Jul 23, 2023 at 10:33 AM Casey Tucker <vim-dev...@256bit.org> wrote:

@chrisbra

hm, can we have tests please? Can we make it a bit more explicit, that <D- is done using the <super> key on non-Macs?

I may need a bit of advice on how to write a test for this. I imagine the main test case would be checking that <D- is recognized on Mac and GTK as a shortcut by the parser and is accepted as a binding by the map command. Would you be able to point me in the right direction with a link to documentation for test writing, or to an existing test that I could adapt towards this case? Are there additional test cases I should be considering?


There are quite a few test cases in src/testdir/test_termcodes.vim for testing various terminal key codes.
For example, refer to the Test_special_term_keycodes() function.  For MS-Windows, the tests are
in the test_mswin_event.vim file.  Refer to the LoopTestKeyArray() function.

Regards,
Yegappan

vim-dev ML

unread,
Jul 23, 2023, 4:28:26 PM7/23/23
to vim/vim, vim-dev ML, Your activity

Hi,

On Sun, Jul 23, 2023 at 10:33 AM Casey Tucker ***@***.***>
wrote:

> @chrisbra <https://github.com/chrisbra>


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/12698/c1646952333@github.com>

zeertzjq

unread,
Jul 23, 2023, 5:33:38 PM7/23/23
to vim/vim, vim-dev ML, Comment

Super key is also supported by kitty keyboard protocol: https://sw.kovidgoyal.net/kitty/keyboard-protocol/#modifiers


Reply to this email directly, view it on GitHub.

You are receiving this because you commented.Message ID: <vim/vim/pull/12698/c1646964739@github.com>

Casey Tucker

unread,
Jul 24, 2023, 4:15:45 AM7/24/23
to vim/vim, vim-dev ML, Push

@dctucker pushed 1 commit.

  • e864c10 add Test_map_super_{quotes,multibyte}


View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/12698/push/14422342715@github.com>

Christian Brabandt

unread,
Jul 24, 2023, 4:22:11 AM7/24/23
to vim/vim, vim-dev ML, Comment

@chrisbra commented on this pull request.


In runtime/doc/map.txt:

> @@ -983,8 +984,16 @@ For the Meta modifier the "T" character is used.  For example, to map Meta-b
 in Insert mode: >
 	:imap <T-b> terrible
 
+1.12 MAPPING SUPER-KEYS					:map-super-keys

|:map-super-keys|


Reply to this email directly, view it on GitHub.

You are receiving this because you commented.Message ID: <vim/vim/pull/12698/review/1542942905@github.com>

chdiza

unread,
Jul 24, 2023, 11:07:17 AM7/24/23
to vim/vim, vim-dev ML, Comment

I would hope that this isn't restricted to GTK* versions, but also would work in the console---assuming the kitty keyboard protocol.


Reply to this email directly, view it on GitHub.

You are receiving this because you commented.Message ID: <vim/vim/pull/12698/c1648092100@github.com>

Casey Tucker

unread,
Jul 24, 2023, 11:37:23 AM7/24/23
to vim/vim, vim-dev ML, Comment

@chdiza I've focused my effort entirely on implemented this for the GTK version, so I can't guarantee that the scope of this PR will grow to accommodate other terminals, but I'm happy to ride in the passenger seat on a larger effort.


Reply to this email directly, view it on GitHub.

You are receiving this because you commented.Message ID: <vim/vim/pull/12698/c1648154016@github.com>

Casey Tucker

unread,
Jul 24, 2023, 11:46:29 AM7/24/23
to vim/vim, vim-dev ML, Push

@dctucker pushed 1 commit.

  • 392e626 correct syntax in map.txt map-super-keys

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/12698/push/14428137286@github.com>

Christian Brabandt

unread,
Jan 25, 2024, 4:49:18 PMJan 25
to vim/vim, vim-dev ML, Comment

Closed #12698 via 92e90a1.


Reply to this email directly, view it on GitHub.

You are receiving this because you commented.Message ID: <vim/vim/pull/12698/issue_event/11602688298@github.com>

Reply all
Reply to author
Forward
0 new messages