108

How to trigger a popup with documentation for identifier under the cursor?

Normally it appears when hovering the identifier using the mouse pointer: enter image description here

I would like to achieve this effect using a command or keyboard shortcut.

The only related commands I found are: trigger completion (which doesn't show the function doc) and trigger parameters hint (which only works when the cursor is inside function call - parameters list).

starball
  • 20,030
  • 7
  • 43
  • 238
Robert Zaremba
  • 8,081
  • 7
  • 47
  • 78
  • 1
    Does this answer your question? [Keyboard shortcut to show hover tooltip](https://stackoverflow.com/questions/32279384/keyboard-shortcut-to-show-hover-tooltip) – Sol Jan 25 '21 at 08:22

7 Answers7

112

This is the editor.action.showHover command. It is bound to cmdk cmdi by default.

Note: Shortcut works by holding down the cmd [ctrl in windows], then while holding press k then i

You can change the keyboard shortcut with a keybinding such as:

{
    "key": "cmd+k ctrl+space",
    "command": "editor.action.showHover",
    "when": "editorTextFocus"
}
shareef
  • 9,255
  • 13
  • 58
  • 89
Matt Bierner
  • 58,117
  • 21
  • 175
  • 206
69

The default shortcut for Trigger Parameter Hints is Ctrl+Shift+Space

Tae Soo Kim
  • 1,019
  • 8
  • 14
  • 3
    This is soooo much easier than ctrl+k ctrl+i – YPOC Nov 14 '21 at 22:59
  • 8
    Even if it was not what Robert asked, this is what I was looking for! On Mac the command is `⌘ + Shift + Space` – Mister Q Feb 10 '22 at 13:56
  • 1
    Ctrl+Shift+Space works when the cursor is at the function parameters list. – J3W Apr 03 '22 at 13:26
  • 2
    [_As a side note_] The same key combination is used _by default_ in **1Password**. So anyone who has 1Password installed should be aware of this moment (both VS Code's and 1Password's shortcuts can be changed if needed of course). – informatik01 May 17 '23 at 06:23
12

You also have, with VSCode 1.40 (Oct. 2019):

Definition Preview Hover from the keyboard

There is a new command Show Definition Preview Hover for better accessibility of the definition preview hover widget, which can be triggered by hovering a symbol with the mouse and pressing a modifier key dependent on the platform and configuration.

Previously, only the command Show Hover was provided, which is equivalent to hovering the mouse cursor over a symbol.
Now, with Show Definition Preview Hover, the detailed hover information can be shown via the keyboard.

https://code.visualstudio.com/assets/updates/1_40/definition-preview-hover.gif

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Note: the theme used in the image is not mentioned in the release note 1.40 page, but it look like https://vscodethemes.com/e/jolaleye.horizon-theme-vscode: https://github.com/jolaleye/horizon-theme-vscode. Slightly more recent version of the same theme: https://github.com/alexandernanberg/horizon-theme-vscode/commits/master – VonC Jan 22 '22 at 21:45
10

To make this more graphic, check these steps: enter image description here

enter image description here

Iván Yoed
  • 3,878
  • 31
  • 44
2

In Visual Studio 2019 for Mac, I couldn't find anything about "hover" in the Key Bindings setting. The relevant command seems to be called "Show quick info" and is bound by default to Cmd + F1.

I know this question is about VSCode but I could only find this question when trying to search for an answer. Therefore I would also like to leave the information here in case somebody finds it useful.

xji
  • 7,341
  • 4
  • 40
  • 61
  • 2
    the question is about Visual Studio Code, not Visual Studio . – Martin Riddar May 27 '20 at 05:29
  • @MartinRiddar Yeah. I was searching for information for Visual Studio and couldn't find any. Therefore I put the info under this question as well since somebody else might also stumble upon this question as well. – xji May 27 '20 at 09:41
  • fair enough, I saw that you updated the answer to include that now :) – Martin Riddar May 27 '20 at 13:36
2

There are multiple ways to trigger the documentation popup:

First: Using shortcut ctrl + space

enter image description here

Second: Using vscode extension:

enter image description here

Here is the documentation:

enter image description here

Haroon Hayat
  • 329
  • 2
  • 4
1

Each answer here demonstrates a different function. Below is a consolidation of every type of helpful popup, the context in which they come up and all the ways I know to trigger them.

These assume default settings.

Function: Display documentation

Shortcut: Ctrlk Ctrli

Scope: Works over named elements - variable and function names (does nothing over literals).

  • Can display function documentation: function documentation
  • or variable or even property information: variable information
  • This is the same pop-up you get when you hover over the element briefly.

Function: Display parameter hints.

Shortcut: CtrlShiftSpace

Scope: Works inside a function call.

parameter hints

  • The cursor must be inside the parenthesis that contain the passed arguments. Does nothing outside that scope.
  • Can also be triggered by typing a comma, as if passing another argument.
  • Up/Down arrows can be used to cycle through overloaded definitions (instead of moving the cursor up and down the document).

Function: Display the code completion menu

Shortcut: CtrlSpace

Scope: Anywhere. Will adapt to the context. In strings will display words only. In code will offer symbol hints - function names, variable names within the current scope, known properties, etc.

code completion menu

  • Is case insensitive.
  • Matches all contained characters - they do not have to be consecutive (see image above).
  • Tab or Enter accepts the currently selected suggestion.
  • Symbol hints can be triggered by just typing letters. Inside strings you must use the keyboard shortcut.
martixy
  • 784
  • 1
  • 10
  • 26