Search code examples
visual-studio-codego-to-definition

How does "Peek-less navigation" work if "Goto Location: Multiple Definitions" is set to "goto" in vscode?


If I use go-to definition in vscode and there are multiple definitions, by default, it will open an inline window to let me peek at each result. The problem I have with it is that switching between definitions in this window takes 3 button presses each, if the definitions are in separate files, because in order to see the definition you have to select it in the tree view, and the tree nodes for the files are collapsed, thus hiding the tree nodes for definitions. So you have to first "un-collapse" the file node, and then select the definition node: enter image description here My desired solution would be for this not to be a hierarchical tree view and instead a flat one, but that doesn't seem to be possible. As a faster way of navigating between the definitions, I changed the setting "Editor/Goto Location: Multiple Definitions" from "peek" to "goto", the tooltip of which says: "Go to the primary result and enable Peek-less navigation to others". My question is:

How does this "Peek-less navigation" between definitions work? I expected this to mean something like, once I go to the primary result, I can now press up/down (for example) to switch between definitions or press something like f4 to go to the next definition. But this doesn't work. How can I navigate between definitions in this case?


Solution

  • After selecting "goto" for "multiple definitions" setting,

    You need to set a keybinding for "editor.gotoNextSymbolFromResult" in Keyboard shortcuts. keyboard shortcut window

    Now whenever "goto definition" is used for a symbol with multiple definitions, status bar will show "Symbol 1 of N, ^F12 for next" and you can use the shortcut for cycling through results. Status bar