如何在vscode中使用vim用户快捷键?

4

vscode > 首选项: 打开设置(JSON)

{  
    "vim.normalModeKeyBindingsNonRecursive": [
       
        {
            "before": ["t", "s"],
            "commands": ["python.sortImports"],
        }
    ]
}

我按照上述步骤设置了它,但它没有起作用。可能出了什么问题? 我在 vim-normal 模式下输入 "t" 和 "s"。 ctrl+alt+s 可以正常工作,但我想要自定义 Vim 快捷键。

2个回答

2
尝试重新安装 vim 扩展 。如果失败了,您可以尝试以下方法:
  1. Are your configurations correct?

Adjust the extension's logging level to 'debug', restart VS Code. As each > remapped configuration is loaded, it is outputted to console. In the Developer > Tools console, do you see any errors?

debug: Remapper: normalModeKeyBindingsNonRecursive. before=0. after=^.
debug: Remapper: insertModeKeyBindings. before=j,j. after=<Esc>.
error: Remapper: insertModeKeyBindings. Invalid configuration. Missing 'after' key or 'command'. before=j,k.

Misconfigured configurations are ignored.

  1. Does the extension handle the keys you are trying to remap?

VSCodeVim explicitly instructs VS Code which key events we care about through > the package.json. If the key you are trying to remap is a key in which vim/vscodevim generally does not handle, then it's most likely that this extension does not receive those key events from VS Code. With logging level adjusted to 'debug', as you press keys, you should see output similar to:

debug: ModeHandler: handling key=A.
debug: ModeHandler: handling key=l.
debug: ModeHandler: handling key=<BS>.
debug: ModeHandler: handling key=<C-a>.

As you press the key that you are trying to remap, do you see it outputted here? If not, it means we don't subscribe to those key events. It is still possible to remap those keys by using VSCode's keybindings.json.

来源: https://marketplace.visualstudio.com/items?itemName=vscodevim.vim#debugging-remappings

这是一个关于程序员常用文本编辑器Visual Studio Code的插件Vim的调试映射功能的介绍页面。

1
我的设置[打开设置(JSON)]没有问题,当我再次运行程序时,这个vim快捷键正常工作了。然而,您提供的信息给了我更多的知识。谢谢。如果有人看到我的问题,你可能可以通过应用上述设置扩展自己的vim快捷键。感谢您的回答。 - ㅇㅅㅇ

0
对于从搜索中寻求如何在vs code中启用vim按键绑定的其他人,我并不需要改变任何vscode设置,仅仅按下command + shift + x打开“扩展”选项卡,搜索“vim”,安装顶部扩展(见下文)。然后,vim按键绑定就可以工作了,无需任何额外步骤(甚至不需要重新启动vscode,这太好了)。

enter image description here


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接