在安装了扩展
vscode-neovim
的 VSCode 中:
我在我的
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
我找到了解决此问题的方法,这涉及设置键盘映射以按顺序执行两个命令:
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'"
}
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)
居中滚动的解决方法
禁用默认实现:
{
"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"
}