1

I am working on OS Ubuntu 22.04 running inside a Virtualbox VM hosted in a windows 10 OS.

Inside the VM, it seems that my VScode has reset some of the user-defined keyboard shortcuts I have previously set.

So I want to re-define them.

I want to change the keyboard shortcut of "Toggle Line Comment", which is set from CTRL + Y to CTRL + ù ( currently CTRL + Y is assigned by the system to "redo", and that is OK ).

enter image description here

So I click on the pencil icon of "Toggle Line Comment",

press the keys combination CTRL + ù

enter image description here

"ù" gets interpreted as "[Backslash]"

press enter

but then I still see assigned CTRL + Y (as if the change was rejected); and from some tests I did, that one is the only combination that manages to toggle comment lines.

I have tryed to restart VScode but nothing changes, I cannot edit the settings from the UI.

So I have tryed to edit them from the keybindings.json

tommaso@tommaso-VirtualBox02:~$ sudo locate keybindings.json    
/home/tommaso/.config/Code/User/keybindings.json

tommaso@tommaso-VirtualBox02:~$ vim /home/tommaso/.config/Code/User/keybindings.json

And the content of the opened file is

[    
    {    
        "key": "ctrl+alt+[Backslash]",    
        "command": "editor.action.blockComment",    
        "when": "editorTextFocus && !editorReadonly"    
    },    
    {    
        "key": "ctrl+shift+a",    
        "command": "-editor.action.blockComment",    
        "when": "editorTextFocus && !editorReadonly"    
    },    
    {    
        "key": "ctrl+shift+7",    
        "command": "-editor.action.commentLine",    
        "when": "editorTextFocus && !editorReadonly"    
    },    
    {    
        "key": "ctrl+[Backslash]",    
        "command": "editor.action.commentLine"    
    }    
]

It is indeed strange that the last {} entry I have added via the UI is missing the "when" key.

Anyway I have edited the content to

[
    {
        "key": "ctrl+alt+[Backslash]",
        "command": "editor.action.blockComment",
        "when": "editorTextFocus && !editorReadonly"
    },
    {
        "key": "ctrl+shift+a",
        "command": "-editor.action.blockComment",
        "when": "editorTextFocus && !editorReadonly"
    },
    {
        "key": "ctrl+shift+7",
        "command": "-editor.action.commentLine",
        "when": "editorTextFocus && !editorReadonly"
    },
    {
        "key": "ctrl+[Backslash]",
        "command": "editor.action.commentLine",
        "when": "editorTextFocus && !editorReadonly"
    }
]

saved,

restarted VScode

but again, the "toggle line comment" gets activated only by CTRL + Y.

The strange thing is that the CTRL + ALT + ù, that is

    {
        "key": "ctrl+alt+[Backslash]",
        "command": "editor.action.blockComment",
        "when": "editorTextFocus && !editorReadonly"
    }

works fine.

It is like VS code cannot load changes from keybindings.json .

What can be blocking the edit?

Tms91
  • 3,456
  • 6
  • 40
  • 74
  • What's the connection between blackslashes and `ù` on your keyboard? It's not clear to me. – starball Feb 02 '23 at 22:45
  • the `ù` is interpreted by VScode as `[Backslash]`, it is maybe weird but it works for the shortcut CTRL + ALT + ù . Why should not it work for CTRL + ù – Tms91 Feb 02 '23 at 22:47
  • Edits will be blocked from the kebindings UI editor if the keybindings.json file has unsaved changes (you'll get a popup notification saying so). – starball Feb 02 '23 at 23:20
  • that is not the case, I actually got the popup once when I was doing things wrong. – Tms91 Feb 02 '23 at 23:24
  • 1
    Please always [edit] clarifications into your question post instead of hiding them in the comments! Comments are for _soliciting_ clarifications- not for providing them. That kind of information is the kind that will save people wasted time trying to understand your problem. – starball Feb 02 '23 at 23:30
  • 1
    Same here, `Enter` is now interpreted as `F3` and some of my shortcuts are screwed since last update. – JJP Feb 07 '23 at 09:01

2 Answers2

0

I believe you would do this like so:

[
    {
        "key": "ctrl+\\",
        "command": "editor.action.commentLine",
        "when": "editorTextFocus && !editorReadonly"
    },
    {
        "key": "ctrl+y",
        "command": "-editor.action.commentLine",
        "when": "editorTextFocus && !editorReadonly"
    },
]
starball
  • 20,030
  • 7
  • 43
  • 238
0

From another machine having the same key VScode shortcut configuration, and having the shotcuts properly working on VScode, I accessed the content of keybinding.json, and it is the following

// Place your key bindings in this file to override the defaultsauto[]
[
    {
        "key": "ctrl+shift+[Backslash]",
        "command": "editor.action.blockComment",
        "when": "editorTextFocus && !editorReadonly"
    },
    {
        "key": "ctrl+shift+a",
        "command": "-editor.action.blockComment",
        "when": "editorTextFocus && !editorReadonly"
    },
    {
        "key": "ctrl+[Backslash]",
        "command": "editor.action.commentLine",
        "when": "editorTextFocus && !editorReadonly"
    },
    {
        "key": "ctrl+shift+7",
        "command": "-editor.action.commentLine",
        "when": "editorTextFocus && !editorReadonly"
    }
]

It is exactly the same content of the one on the other machine, for which it was not working properly.

So the problem is machine-related.

So the end I have set the key combination ctrl+à for the toggle line comment, and it is OK.

I think the problem is somehow linked to how VScode interprets a key:

I have an italian keyboard having a key which contains "§" and "ù", but VS code somehow interprets it as "[Backslash]".

Once again I want to underline that it is strange to me that

  1. ctrl+alt+ù

is correctly got as change by VScode, while

  1. ctrl+ù

is rejected ( the UI swithces the combination automatically to "ctrl"+"y", while on the keybindings.json it is actually written "ctrl+[Backslash]" )

even if in both cases 1) and 2), "ù" is interpreted as "[Backslash]".

Tms91
  • 3,456
  • 6
  • 40
  • 74