[英]Vim for VSCode: Remap ctrl + e to go to end of line in insert mode
我将Vim 与 VSCode 一起使用。
在插入模式下,我试图重新映射ctrl+e
以到达行尾。 这是我在settings.json
中写的:
"vim.insertModeKeyBindingsNonRecursive": [{ "before": ["<C-o>", "$"], "after": ["<C-e>"] }]
不幸的是,这在某种程度上不起作用。 我怎样才能重新映射这个?
编辑:根据答案,我也尝试过
"vim.insertModeKeyBindingsNonRecursive": [ { "before": ["<C-e>"], "commands": { "command": "cursorLineEnd" } } ]
和
"vim.insertModeKeyBindingsNonRecursive": [{ "before": ["<C-e>"], "commands": "cursorLineEnd" }]
这也都没有用。
尝试使用commands
选项:
"vim.insertModeKeyBindingsNonRecursive": [{
"before":[
"<C-e>"
],
"after":[],
"commands":[
{
"command":"cursorEnd",
"args":[]
}
]
}]
更新:我尝试了几种<C-...>
组合,经过几个小时的摆弄,我得出的结论是某些Ctrl
绑定根本不起作用。 我尝试了多种变体都无济于事,任何其他组合键似乎都可以正常工作,例如:
"vim.insertModeKeyBindingsNonRecursive": [
{
"before": [
"j",
"k"
],
"commands": [
"cursorLineEnd",
]
}
]
我现在给你的建议是避免Ctrl
重映射,改用<leader>
。 您还可以适当地组织这些发现并在 GitHub 上打开一个新问题。
聚苯乙烯
您可以在文件 -> 首选项 -> 键盘快捷键中检查命令名称:
这对我有用:
VSCode 1.37.1(2019 年 7 月)
VSCodeVim v1.9
首先告诉VSCodeVim扩展取消处理Ca
和Ce
。 这会将这些控制键委托给 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"
},
]
在你的keybindings.json
试试这个:
{
"key": "ctrl+a",
"command": "cursorLineStart",
"when": "textInputFocus && vim.mode == 'Insert'"
},
{
"key": "ctrl+e",
"command": "cursorLineEnd",
"when": "textInputFocus && vim.mode == 'Insert'"
}
我发现递归映射有效:
"vim.insertModeKeyBindings": [
{
"before": [
"<C-e>"
],
"commands": [
"cursorEnd"
],
},
{
"before": [
"<C-a>"
],
"commands": [
"cursorHome"
],
}
],
尽管它们并不理想。
将以下内容添加到settings.json
对我有用:
"vim.inserModeKeyBindings": [
{
"before": ["<C-e>"],
"after": ["<esc>", "$", "a"]
}
]
在 keybindings.json 中:
[
{
"key": "ctrl+a",
"command": "cursorHome",
"when": "editorTextFocus && vim.active && !inDebugRepl && vim.mode == 'Insert'"
},
{
"key": "ctrl+e",
"command": "cursorEnd",
"when": "editorTextFocus && vim.active && !inDebugRepl && vim.mode == 'Insert'"
}
]
在 2020-05-15 的这个线程中试过答案,没有一个仍然有效。 发现这个问题https://github.com/VSCodeVim/Vim/issues/3126包含一个解决方法,它对我有用。
我的 vscode 版本:1.45.0
感谢问题作者https://github.com/paupalou
首先:在你的setting.json
中设置vim.useCtrlKeys": true,
然后:
"vim.insertModeKeyBindingsNonRecursive": [
{
"before": ["<C-e>"],
"after": [],
"commands":[
{
"command":"cursorLineEnd",
"args":[]
}
]
},
{
"before": ["<C-a>"],
"after": [],
"commands":[
{
"command":"cursorLineStart",
"args":[]
}
]
}
],
完成你的旨意
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.