这对我有用:
VSCode 1.37.1(2019 年 7 月)
VSCodeVim v1.9
首先告诉 VSCodeVim 扩展取消处理 C-a
和C-e
. 这会将这些控制键委托给 VSCode 而不是扩展:
// In your settings.json
"vim.handleKeys": {
"<C-a>": false,
"<C-e>": false
},
现在只需在 VSCode 中重新映射这些键:
// In your keybindings.json
[
{
"key": "ctrl+a", // default is Home
"command": "cursorHome",
"when": "textInputFocus"
},
{
"key": "ctrl+e", // default is End
"command": "cursorEnd",
"when": "textInputFocus"
},
{
"key": "ctrl+a", // default is Home
"command": "extension.vim_home",
"when": "editorTextFocus && vim.active && !inDebugRepl && vim.mode != 'Insert'"
},
{
"key": "ctrl+e", // default is End
"command": "extension.vim_end",
"when": "editorTextFocus && vim.active && !inDebugRepl && vim.mode != 'Insert'"
},
]
我发现前两个绑定在正常和插入模式下工作,但不是在可视模式下(它有点移动光标但没有选择任何内容)。最后两个确保它也可以在可视模式下工作。
编辑:我发现简单地删除工作中的最后一个条件vim.mode != 'Insert'
并且when
更清洁。所以代替上面的键绑定,简单地:
// In your keybindings.json
[
{
"key": "ctrl+a",
"command": "extension.vim_home",
"when": "editorTextFocus && vim.active && !inDebugRepl"
},
{
"key": "ctrl+e",
"command": "extension.vim_end",
"when": "editorTextFocus && vim.active && !inDebugRepl"
},
]