VSCode + neovim:如何上下跳转半页并垂直居中屏幕?

问题描述 投票:0回答:3

在安装了扩展

vscode-neovim
的 VSCode 中:

  • 如何设置键绑定,例如,ctrl+u将屏幕向上移动半页,然后垂直居中?
  • 向下和整页向上/向下反之亦然。

我在我的

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."
  },
]

但是经过这些更改后,半页向上和向下命令现在会跳转 100 行(而不是像以前那样跳转 20 行)。

GitHub 上的相关问题:https://github.com/vscode-neovim/vscode-neovim/issues/1039

visual-studio-code vscode-extensions neovim
3个回答
3
投票

解决方法

我找到了解决此问题的方法,这涉及设置键盘映射以按顺序执行两个命令:

  1. 安装多命令扩展
  2. 转到键盘快捷键 JSON。
  3. 使用以下内容为
    Ctrl+d
    Ctrl+u
    设置新的按键绑定:
{
  "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'"
}

0
投票

问题

问题似乎与

vscode-scrolling.vim
文件中注释掉的代码有关:

" 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)

0
投票

居中滚动的解决方法

禁用默认实现:

  {
    "key": "ctrl+u",
    "command": "-vscode-neovim.ctrl-u",
    "when": "editorTextFocus && neovim.ctrlKeysNormal.u && neovim.init && neovim.mode != 'insert' && editorLangId not in 'neovim.editorLangIdExclusions'"
  },
  {
    "key": "ctrl+d",
    "command": "-vscode-neovim.ctrl-d",
    "when": "editorTextFocus && neovim.ctrlKeysNormal.d && neovim.init && neovim.mode != 'insert' && editorLangId not in 'neovim.editorLangIdExclusions'"
  }

使用多命令滚动并将光标移动到中心:

设置.json

  "multiCommand.commands": [
    {
      "command": "multiCommand.pageUp",
      "sequence": [
        {"command": "editorScroll", "args": {"to": "up", "by": "wrappedLine", "value": 32 }},
        { "command": "cursorMove", "args": { "to": "viewPortCenter" } }
      ]
    },
    {
      "command": "multiCommand.pageDown",
      "sequence": [
        {"command": "editorScroll", "args": {"to": "down", "by": "wrappedLine", "value": 32 }},
        { "command": "cursorMove", "args": { "to": "viewPortCenter" } }
      ]
    }
  ],

键绑定.json

  {
    "key": "ctrl+u",
    "command": "multiCommand.pageUp",
    "when": "editorTextFocus"
  },
  {
    "key": "ctrl+d",
    "command": "multiCommand.pageDown",
    "when": "editorTextFocus"
  }
© www.soinside.com 2019 - 2024. All rights reserved.