Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't navigate help reference using Ctrl-] on a Belgian keyboard #11831

Closed
vds2212 opened this issue Jan 16, 2023 · 22 comments
Closed

Can't navigate help reference using Ctrl-] on a Belgian keyboard #11831

vds2212 opened this issue Jan 16, 2023 · 22 comments

Comments

@vds2212
Copy link

vds2212 commented Jan 16, 2023

Steps to reproduce

  1. Start Vim with a Belgian keyboard
  2. Navigate to the help file: `:help expand()
  3. Move the cursor to TRUE
  4. Hit Ctrl-$ (the equivalent to Ctrl-] on a Belgian keyboard)

Vim cursor move to the end of the line where we expect to go to the definition of TRUE

Expected behaviour

This was the behavior with Vim 8.2 and is the behavior with Neovim

Version of Vim

gVim 9.0.1164 (I don't have the problem with the console version of vim)

Environment

Operating System: Windows 10

Logs and stack traces

No response

@vds2212 vds2212 added the bug label Jan 16, 2023
@brammool
Copy link
Contributor

brammool commented Jan 16, 2023 via email

@vds2212
Copy link
Author

vds2212 commented Jan 16, 2023

The considered key is CTRL-] (Jump to definition) and not CTRL-[ as in your list of question.

In a Belgian keyboard the ] is produced using AltGr + $

But in previous version of Vim and in the actual version of Vim you can get the behavior of CTRL-] (jump to definition) by hitting CTRL-$

The previous case was indeed CTRL-[ that we used to reached using CTRL-^ (the ^ being a deadkey in the Belgium keyboard)

@ant0sha
Copy link
Contributor

ant0sha commented Jan 16, 2023

Vivian, as far as I remember I also found that and it was possible to work it around with 'nmap <c-$> <c-]>' or something like that?

Edit: (my finding was in w32 gvim)

@zewpo
Copy link
Contributor

zewpo commented Jan 16, 2023

Is this something we can write tests for? for example in test_mswin_event.vim? @ant0sha Is this possibly helped by your open PR about switching keyboard layouts in gVim?

@ant0sha
Copy link
Contributor

ant0sha commented Jan 17, 2023

Is this something we can write tests for? for example in test_mswin_event.vim? @ant0sha Is this possibly helped by your open PR about switching keyboard layouts in gVim?

Using my PR for switching kbd layouts one can test such things, yes.

But I fear kbd layout(s) need to be also configured in the OS of the machine, where test is running. Probably therefore it always failed in CI - not sure though. Locally it worked fine.

@vds2212
Copy link
Author

vds2212 commented Jan 18, 2023

I confirm that the workaround @ant0sha is working

nnoremap <C-$> <C-]>

@vds2212
Copy link
Author

vds2212 commented Jan 18, 2023

To answer @brammool:
iCtrl-vCtrl-$ inserts $

@ant0sha
Copy link
Contributor

ant0sha commented Jan 18, 2023

Is that in the console, Windows Terminal or in the GUI?

According to @vds2212 (chatted outside of tracker) "It works fine in console but not in gVim"

@brammool
Copy link
Contributor

brammool commented Jan 18, 2023 via email

@ant0sha
Copy link
Contributor

ant0sha commented Jan 18, 2023

@brammool, proposed change of may_adjust_key_for_ctrl() would most probably solve it for w32 gvim and GTK gui. A bit unclear is how it is about plain X11 (motif) - motif front-end handled ctrl_dead_circumflex already as ESC, no idea how - so for that ctrl-$ topic similar surprises are possible. Anyway if nothing interfere, will try those 3 front-ends this weekend.

No idea how it can influence w32 console or WT, or classical Unix pty - that's question for others. Anyway a bit disturbing fact is that it works already without your proposed patch in w32 console (and my best guess that it works without patch in classical Unix pty as well, otherwise there would be long ago complains from Belgium?). In classical pty (xterm under Linux) I can try it as well, not pretending to understand code though.

Are there more front-ends?

@tonymec
Copy link

tonymec commented Jan 18, 2023

On a Belgian keyboard, Ctrl-] is not Ctrl-$ but Ctrl-AltGr-$ (I have such a keyboard and it took me literally years to find that).

If you can't access that key combo, or if it is too complex for you, you can do like I did before I found out how to produce a Ctrl-] on a Belgian keyboard: add to your vimrc

map <F9> <C-]>
map! <F9> <C-]>

(You may use anything else, preferably an F key, instead of F9). This way, you can (with this example) use F9 not only to jump to a tag (including a help tag) but also (in Insert mode) to trigger an abbreviation.

Best regards,
Tony.

@tonymec
Copy link

tonymec commented Jan 18, 2023

P.S. Now I know how to get Ctrl-] on a "raw" Belgian keyboard, but in Vim or gvim I still use F9 as above.

@vds2212
Copy link
Author

vds2212 commented Jan 20, 2023

Here are the result of my tests:

Ctrl-* behave like Ctrl-] on:

  • Windows 10 Vim (console)

Ctrl-* doesn't behave like Ctrl-] on:

  • Windows 10 gVim
  • Linux (Ubuntu) gVim
  • Linux (Ubuntu) Vim (console)

@tonymec,

In my tests:

  • Ctrl-AltGr-* does behave like Ctrl-] on Linux (Ubuntu) but
  • Ctrl-AltGr-* doesn't behave like Ctrl-] on Windows 10

@ant0sha
Copy link
Contributor

ant0sha commented Jan 22, 2023

@brammool:

I wonder if we can make this change without breaking it for other
environments:

--- a/src/misc2.c        2023-01-14 21:07:04.002952303 +0000
+++ b/src/misc2.c     2023-01-18 13:57:20.389467164 +0000
@@ -1559,6 +1559,13 @@
        return '^';
     if (key == '-')
        return '_';
+
+    // On a Belgian keyboard AltGr $ is ']', on other keyboards '$' can only be
+    // obtained with Shift.  Assume that '$' without shift implies a Belgian
+    // keyboard, where CTRL-$ means CTRL-].
+    if (key == '$' && (modifiers & MOD_MASK_SHIFT) == 0)
+       return ']';
+
     return key;
 }

Short summary for the patch:

  • Motif - don't work, needs improvement, although apparently also
    not breaks anything
  • GKT3 - works fine
  • PTY (vim in xterm) - probably noop, concerns, but hopefully not
    breaks anything
  • W32 GUI - works fine
  • W32 CMD.exe - UNTESTED
  • W32 WT (windows terminal) - UNTESTED

TLDR description:

Here are results:

-------------+------------+------+------+---------+
             |            |AZERTY|AZERTY|AZERTY   |
Front-End    | Version    |C-^ as|C-$ as|C-AltGr-$|
             |            |EN C-[|EN C-]|as EN C-]|
-------------+------------+------+------+---------+
Motif        | v9.0.1224  |   Y  |   N  | Y       |
Motif        | v9.0.1224p |   Y  |   N  | Y       |
GTK3         | v9.0.1224  |   Y  |   N  | Y       |
GTK3         | v9.0.1224p |   Y  |   Y! | Y       |
W32 GUI old  | v8.2.4005  |   Y  |   Y  | N       |
W32 GUI new  | v9.0.1224  |   Y  |   N  | N       |
W32 GUI new  | v9.0.1224p |   Y  |   Y! | N       |
W32 CMD.exe  | -          |   -  |   -  | -       |
W32 WT       | -          |   -  |   -  | -       |
PTY on xterm | v9.0.1224  |   Y  |   N  | Y       |
PTY on xterm | v9.0.1224p |   Y  |   N  | Y       |
-------------+------------+------+------+---------+

Patch on Motif don't quite work - although I see the "key" value
returned by may_adjust_key_for_ctrl(...) is altered, but later,
after "key = may_adjust_key_for_ctrl(...)" assignment, "key" is
not used to feed VIM internal keys buffer, but rather (unaltered)
string[] array is used for that: "add_to_input_buf(string, len);"

Although not quite working on Motif this seems not to break
anything. After "key" is modified, it used in two subsequent
calls. (By the way, that Motif code looks not so nice already
before patch since may_adjust_key_for_ctrl may change the
value of key even before patch). 2 subsequent calls are:

  • may_remove_shift_modifier - it should be noop because
    code of patch in may_adjust_key_for_ctrl is only triggered
    for the case when SHIFT is hold.

  • check_for_interrupt - seems to be streamlined to catch
    Ctrl_C cases only, therefore should not interfere with neither
    <C-$> nor with <C-]>

Patch do not works for PTY on xterm - code in
may_adjust_key_for_ctrl() is not called at all in that case in my
tests. My understanding of check_termcode() function is not
enough yet to tell more for this case, I am interested to look on
it on the long run but it will take time. So here potentially it
may be get called for corner cases, when in PTY some specific key
protocolls are activated?

GTK3 and W32 GUI variants both work fine with patch. Patch is
changing behavior of AZERTY <C-$> exactly as we like it to.

If someone would please do test of this patch with W32 CMD.exe
and W32 WT (windows terminal) front-ends? According to Vivian at
least one of them already works even without patch. What about
another? Does patch breaks something for them?

"AZERTY <C-$> acts like QWERTY <C-]>"
behavior seems to be originally only restricted to (some? all?)
windows front-end versions and was not observed in any of unix
front ends so far. On the contrary, in the UNIX world,
workaround, pointed by @tonymec (C-AltGr-$) seems to
be the way of going until now.

Patch proposed is a step towards harmonization.

@brammool
Copy link
Contributor

brammool commented Jan 23, 2023 via email

@vim-ml
Copy link

vim-ml commented Jan 25, 2023 via email

@brammool
Copy link
Contributor

brammool commented Jan 25, 2023 via email

@ant0sha
Copy link
Contributor

ant0sha commented Jan 28, 2023 via email

@vds2212
Copy link
Author

vds2212 commented Feb 11, 2023

Thanks Anton.

Can you tell me what is the status of the patch?
Is it already integrated into the trunk?
Is there a pull request that I can test?

Best regards,
Vivian.

@brammool
Copy link
Contributor

I'm not 100% sure this won't break something, but there is no way to find out.
Let me just commit the change and await comments.

@vds2212
Copy link
Author

vds2212 commented Feb 11, 2023

Thanks.
I have compiled a version for Windows and it solves the problem :-)

@ychin
Copy link
Contributor

ychin commented Mar 1, 2023

Just for reference, just tried this out on the Mac. It "works", in that Ctrl-$ does indeed trigger Ctrl-] in Vim. That said I looked it up and seems like the macOS keyboard has it such that the way to input "]" is by doing Option-Shift-<Minus>, not AltGr-] (there isn't really an AltGr on the Mac, as the Option key serves some of the functionality of it) … This new behavior is probably fine, as I imagine Belgian macOS Vim users would not want to be doing Ctrl-Option-Shift- all the time, and Ctrl-$ isn't mapped to anything anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants