This is what worked for me:
VSCode 1.37.1 (July 2019)
VSCodeVim v1.9
First tell VSCodeVim extension to unhandle C-a
and C-e
. This will delegate those control keys to VSCode instead of the extension:
// In your settings.json
"vim.handleKeys": {
"<C-a>": false,
"<C-e>": false
},
Now simply remap those keys in 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'"
},
]
I found that the first two bindings work in normal and insert mode, but not in visual mode (it sort of moves the cursor but nothing gets selected). The last two ensures it also works in visual mode.
Edit: I found that simply removing the last condition vim.mode != 'Insert'
in when
works and is much cleaner. So instead of the keybindings above, simply:
// 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"
},
]
"vim.insertModeKeyBindingsNonRecursive": [ { "before": ["<C-e>"], "commands": { "command": "cursorLineEnd" } } ]
, becausecursorLineEnd
is more what I'm looking for. Unfortunately, it also doesn't work :( – Amiss