Search code examples
visual-studio-codecommandkeyboard-shortcuts

Is there a way to see what command is run when you press a key?


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?


Solution

  • 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.)