48

In vscode when I mouse hover on let's say, a method call or property it will display some information. I can trigger same thing with keyboard shortcut CMD+H (on mac).

Now with the mouse when I hover while holding the CMD key it will display more information. How to trigger this (CMD+mouse hover) equivalent with keyboard ?

(I'm aware of ALT+F12, but it's not exactly the same trigger.)

Sridhar Ratnakumar
  • 81,433
  • 63
  • 146
  • 187
Robert Brax
  • 6,508
  • 12
  • 40
  • 69
  • Does this answer your question? [Keyboard shortcut to show hover tooltip](https://stackoverflow.com/questions/32279384/keyboard-shortcut-to-show-hover-tooltip) – starball Aug 12 '23 at 01:57

5 Answers5

82

Per official docs, the binding for 'Show Hover' is:

⌘K ⌘I

Remember that ⌘K is a 'chord', so do that first (Code will show "⌘K was pressed. Waiting for second key of chord..."), and then ⌘I.

Hope this helps. It's not the most elegant of bindings, but nothing to stop you changing it!

Note:-

For VSCodeVim users, this is: gh.

For Windows users, this is: Ctrl + K Ctrl + I

abhay tripathi
  • 3,547
  • 4
  • 20
  • 25
Jack Clark
  • 837
  • 5
  • 2
  • 3
    Thanks but that's not it. When you hover with your mouse while holding the cmd button, you will notice it's not the same display as simple hover. I was aware of this hover display which I set to cmd+h..... but what I try to get is the one you get with hover mouse while holding cmd. – Robert Brax Jun 13 '16 at 08:44
  • Did you get the answer for this @RobertBrax? – sathishvj Jul 11 '18 at 15:15
  • For me `⌘K ⌘I` shows the "Show Hover" while `gh` with VSCodeVim shows something else like a variable's type hint. – vdi Nov 25 '20 at 08:33
14

This answer elaborates on Jack's helpful answer by pointing out the command palette command and how to override its shortcut.

Open the command palette and type "show hover" to find the command.

enter image description here

The default shortcut does not work for me, so I added an override of Ctrl + Space + H.

To add your own override, open the command palette and type "keyboard shortcuts". That opens the shortcut editor. This is how mine looks.

// Place your key bindings in this file to override the defaults
[
    {
        "key": "ctrl+space ctrl+h",
        "command": "editor.action.showHover",
        "when": "editorTextFocus"
    }
]
Shaun Luttin
  • 133,272
  • 81
  • 405
  • 467
3

There's a pull request to add this functionality, but it hasn't landed yet: https://github.com/Microsoft/vscode/pull/59260

Kit Westneat
  • 192
  • 2
  • 7
2

I think you are looking for keyboard shortcut for 'Definition Preview'.

  • command name: Show Definition Preview Hover
  • command: editor.action.showDefinitionPreviewHover

To set a keyboard shortcut:

  1. Open keyboard shortcuts
  2. Search for Show Definition Preview Hover
  3. Set your preferred shortcut
  4. Add editorTextFocus to when expression

Or you can append this to your keybindings.json:

{
    "key": "ctrl+alt+;",
    "command": "editor.action.showDefinitionPreviewHover",
    "when": "editorTextFocus"
}

Here ctrl+alt+; is shortcut key I have selected. You add your own.

Usefull reference: https://code.visualstudio.com/updates/v1_40#_definition-preview-hover-from-the-keyboard

Eye Sight
  • 43
  • 6
  • This is the real answer, thank you, that exactly what I needed, using it right now. – Alan Miguel Rocha Oct 31 '21 at 15:02
  • It's weird that it only has so many upvotes, I think this is the actual answer – szeb May 04 '22 at 11:33
  • For some reason, `cmd+click` shows extra type definition information for me but `Show Definition Preview Hover` does not, anyone know why? – PGT May 28 '23 at 03:59
2

If you're using VSCodeVim, you can add this to your settings.json

"vim.normalModeKeyBindingsNonRecursive": [
    {
      "before": ["g", "H"],
      "commands": [
        { 
          "command": "editor.action.showDefinitionPreviewHover" 
        }
      ]
    }
]

By default if you enter gh it will open in hover state. I have it configured so that if I press gH it shows me the advanced info.