2

I want to remap my keys in Visual Studio Code, but can't figure out what commands are run in some cases.

For example, if I'm in the find widget (context findInputFocussed==true) and want to go to the start of the input text I can press home, but I can't seem to find the command hooked up to the home button to take the cursor to the start of the input (I've remapped all commands linked to the home button). Another example is pressing up in the terminal to get the previous command.

How can find the command so I can remap them to my own keys?

Ruan
  • 163
  • 1
  • 8
  • Do I understand correctly that you're asking about the case where you have unbound or rebound all of the Home bindings in Keyboard Shortcuts, but Home continues to do its default behavior in the Find widget? – Scott McPeak Sep 05 '19 at 23:43
  • You picked two bad examples as I don't think vscode has much if anything to do with their functionality. The `upArrow` in the terminal is a shell command history shortcut and not functionality that vscode itself provides and thus wouldn't appear in any of vscode's shortcuts or commands documentation. – Mark Sep 07 '19 at 02:21
  • The `home` command is just an html element's built-in command - like a textbox, input, etc. Like here in this SO comment textarea. It isn't a vscode command really. And so I am not surprised it isn't listed in vscode's shortcut commands. There is a `cursorHome` command which could delete but that doesn't stop the find widget home functionality. – Mark Sep 07 '19 at 02:24
  • I assume you know about the "record Keys" option in the Keyboard Shortcuts page? – Mark Sep 07 '19 at 02:31
  • @Scott yes, I rebound all of them. – Ruan Sep 07 '19 at 04:17
  • @Mark I assumed something like that (that they are built in commands). Would still like to know how I could remap them though... – Ruan Sep 07 '19 at 04:20
  • @Mark does the "record Keys" refer to the functionality to filter the shortcuts based on your key presses? – Ruan Sep 07 '19 at 04:24
  • Yes: https://code.visualstudio.com/updates/v1_28#_record-and-search-keyboard-shortcuts – Mark Sep 07 '19 at 14:10
  • I know it is really tangential to your question but you can bind your own keysequence to terminal up arrow to get previous command. See my answer at https://stackoverflow.com/a/55336498/836330 . I use this command all the time. – Mark Sep 08 '20 at 02:56
  • Does this answer your question? [How to debug keybinds in Visual Studio Code](https://stackoverflow.com/questions/46140269/how-to-debug-keybinds-in-visual-studio-code) – Britt Selvitelle Oct 19 '20 at 17:56

2 Answers2

3

I think the best answer to the question asked in the title, "is there a way to see the command", is no. This was filed as VSCode Issue #38602: Add feature to describe keybinding by pressing said key(s), which was closed as "duplicate", but what they really mean is "unnecessary".

Why unnecessary? The presumption is you can search for your key of interest in the keybinding UI (VSCode Issue #57935: Search in keybindings editor by pressing keyboard shortcut), as referenced in these questions:

However, the body of the question focuses on two examples that fall outside the scope of the existing questions and answers, namely keys whose behavior is not determined by going through the VSCode keybinding system. Specifically, we have:

  • Pressing Home while the Find box is focused.
  • Pressing in the Terminal window.

Not only is there no "describe key" for these, but as far as I can tell through experimentation, it is not possible bind different keys to their functionality. For example, Home is bound by default to the cursorHome command, but binding something else to cursorHome, for example Ctrl+P, does not result in being able to go to the start of the Find box by pressing that new combination. As Mark notes, these bindings are presumably coming from some lower-level component infrastructure, and the commands the keys are bound to by default can't substitute for it. I found something similar regarding the Tab key.

Consequently, if your ultimate goal is to be able to press different keys to accomplish those things, you'll probably need to file a new issue with the VSCode team. (I didn't see anything existing after a cursory search of the issues.)

Scott McPeak
  • 8,803
  • 2
  • 40
  • 79
  • Hi Scott, thanks for the answer. I will follow up with the VSCode team. I think it would be nice if some of those built-in actions were exposed, if possible. – Ruan Sep 09 '19 at 09:17
1

This information is mostly already in the comments to the question, and it doesn't necessarily cover cases where the particular functionality may be coming from the OS, not VSCode (which is potentially the case for the Home key in the original question).

This is what I have done to give me something like describe-key in Emacs. In keybindings.json I have:

[
    // ...snip...

    // Show the keybinding GUI and "record keys" if you're already in the
    // keybinding GUI
    //
    // To see all bindings for a key or key combination (from any ordinary
    // editor), do `C-h C-k C-h C-k` then the key(s) you're interested in.
    { "key": "ctrl+h ctrl+k", "command": "workbench.action.openGlobalKeybindings", "when": "!inKeybindings" },
    { "key": "ctrl+h ctrl+k", "command": "keybindings.editor.recordSearchKeys", "when": "inKeybindings" },

    // describe-key - Toggle the debug keybindings console
    //
    // It's noisy, but it does show you what binding is actually executed for a
    // keypress in a particular context:
    // https://code.visualstudio.com/docs/getstarted/keybindings#_troubleshooting-keybindings
    { "key": "ctrl+h ctrl+shift+k", "command": "workbench.action.toggleKeybindingsLog" },

    // ...snip...
]
Nick Frezynski
  • 640
  • 7
  • 10