skip to Main Content

In VSCode with the extension vscode-neovim installed:

  • How to set up the keybindings so that, for example, ctrl+u moves the screen a half-page up, and then centers it vertically?
  • Vice-versa for down and full-page up/down.

I tried this in my keybindings.json:

[
  // disable the actual ctrl-u
  {
    "key": "ctrl+u",
    "command": "-vscode-neovim.ctrl-u",
    "when": "editorTextFocus && neovim.ctrlKeysNormal && neovim.init && neovim.mode != 'insert'"
  },

  // send the ctrl-u + z. for centering
  {
    "key": "ctrl+u",
    "command": "vscode-neovim.send",
    "when": "editorTextFocus && neovim.ctrlKeysNormal && neovim.init && neovim.mode != 'insert'",
    "args":  "<C-u>z."
  },
]

But after these changes, half-page up and down commands now jump 100 lines (instead of 20 like before).

Related issue on GitHub: https://github.com/vscode-neovim/vscode-neovim/issues/1039

2

Answers


  1. Chosen as BEST ANSWER

    Problem

    The problem seems to be related to the commented-out code from the vscode-scrolling.vim file:

    " Disabled due to scroll problems (the ext binds them directly)
    " nnoremap <silent> <expr> <C-d> VSCodeExtensionCall('scroll', 'halfPage', 'down')
    " xnoremap <silent> <expr> <C-d> VSCodeExtensionCall('scroll', 'halfPage', 'down')
    " nnoremap <silent> <expr> <C-u> VSCodeExtensionCall('scroll', 'halfPage', 'up')
    " xnoremap <silent> <expr> <C-u> VSCodeExtensionCall('scroll', 'halfPage', 'up')
    
    [...] (same for full page and line)
    

  2. Workaround

    I found a workaround for this problem, this involves setting the keymaps to execute both commands as a sequence:

    1. Install the multi-command extension.
    2. Go to your Keyboard Shortcuts JSON.
    3. Set new keybindings for Ctrl+d and Ctrl+u with the following:
    {
      "key": "ctrl+d",
        "command": "extension.multiCommand.execute",
        "args": {
          "sequence": [
          {
            "command": "vscode-neovim.send",
            "args": "<C-d>"
          },
          {
            "command": "vscode-neovim.send",
            "args": "zz"
          }
          ]
        },
        "when": "editorTextFocus && neovim.ctrlKeysNormal && neovim.init && neovim.mode != 'insert'"
    },
    {
      "key": "ctrl+u",
      "command": "extension.multiCommand.execute",
      "args": {
        "sequence": [
        {
          "command": "vscode-neovim.send",
          "args": "<C-u>"
        },
        {
          "command": "vscode-neovim.send",
          "args": "zz"
        }
        ]
      },
      "when": "editorTextFocus && neovim.ctrlKeysNormal && neovim.init && neovim.mode != 'insert'"
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search