[英]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.