How to enable <C-k> to "scroll up" in code sugguestions/hints with vscode vim instead of using arrow keys?
Asked Answered
S

1

8

VScodevim has extension.vim_ctrl+j by default mapped to Ctrl+j which allows you do navigate down pop-up code suggestion windows (triggered by hitting Ctrl+Space in insert mode) like this:

image

It also has extension.vim_ctrl+k mapped to Ctrl+k but this binding down not work, so I cannot scroll up pop-up code suggestion windows. in insert mode defaults to entering a digraph but simply adding something like this

    {
      "before": ["<C-k>"],
      "after": ["extension.vim_ctrl+k"]
    }

to my settings.json does not work since although it removes the digraph functionality, from what I understand, whenever I now press Ctrl+k in insert mode, VSCode will consult the settings.json, find the mapping of to "extension.vim_ctrl+k" which points it back to settings.json in a sort of infinite loop.

:h i_ctrl-j in vim reveals this keybind to be mapped to "Begin new line" so it seems VScode interprets "Begin new line" as navigating down a pop-up window in insert mode instead of it's usual vim behaviour of creating a new line and moving the cursor there, although not sure this is how it works. In any case, I could not find an equivalent vim command that perhaps VSCode could use to scroll up in pop-up windows. Any help would be much appreciated!

Synder answered 6/3, 2022 at 16:46 Comment(0)
P
7

I got this working by copying the existing default keybinds for ctrl+p and ctrl+n which are used throughout VSCode by default for scrolling up and down.

I've used alt here in my keybinds.json file but you can easily replace it with ctrl to achieve what you want

keybinds.json

// Down Motion
{
  "key": "alt+j",
  "command": "cursorDown",
  "when": "textInputFocus"
},
{
  "key": "alt+j",
  "command": "showNextParameterHint",
  "when": "editorFocus && parameterHintsMultipleSignatures && parameterHintsVisible"
},
{
  "key": "alt+j",
  "command": "selectNextSuggestion",
  "when": "suggestWidgetMultipleSuggestions && suggestWidgetVisible && textInputFocus"
},
{
  "key": "alt+j",
  "command": "list.focusDown",
  "when": "listFocus && !inputFocus"
},
{
  "key": "alt+j",
  "command": "workbench.action.quickOpenSelectNext",
  "when": "inQuickOpen"
},

// Up Motion
{
  "key": "alt+k",
  "command": "cursorUp",
  "when": "textInputFocus"
},
{
  "key": "alt+k",
  "command": "showPrevParameterHint",
  "when": "editorFocus && parameterHintsMultipleSignatures && parameterHintsVisible"
},
{
  "key": "alt+k",
  "command": "selectPrevSuggestion",
  "when": "suggestWidgetMultipleSuggestions && suggestWidgetVisible && textInputFocus"
},
{
  "key": "alt+k",
  "command": "list.focusUp",
  "when": "listFocus && !inputFocus"
},
{
  "key": "alt+k",
  "command": "workbench.action.quickOpenSelectPrevious",
  "when": "inQuickOpen"
}
Pyramid answered 22/8, 2022 at 18:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.