Search code examples
vimvisual-studio-codevscodevim

Vim for VSCode: Remap ctrl + e to go to end of line in insert mode


I'm using Vim with VSCode.

I'm trying to remap ctrl+e to got to the end of the line when in insert mode. Here is what I wrote in my settings.json:

"vim.insertModeKeyBindingsNonRecursive": [{ "before": ["<C-o>", "$"], "after": ["<C-e>"] }]

Unfortunately, this somehow doesn't work. How can I remap this?

Edit: Based on the answers, I also tried

"vim.insertModeKeyBindingsNonRecursive": [ { "before": ["<C-e>"], "commands": { "command": "cursorLineEnd" } } ]

and

"vim.insertModeKeyBindingsNonRecursive": [{ "before": ["<C-e>"], "commands": "cursorLineEnd" }]

which also both didn't work.


Solution

  • Try using the commands option instead:

    "vim.insertModeKeyBindingsNonRecursive": [{
           "before":[
              "<C-e>"
           ],
           "after":[],
           "commands":[
              {
                 "command":"cursorEnd",
                 "args":[]
              }
           ]
        }]
    

    Update: I have attempted several <C-...> combinations and after a couple of hours of fiddling I've come to the conclusion that some Ctrl bindings simply do not work. I've tried multiple variations to no avail, and any other key combination seems to work flawlessly, see this for example:

    "vim.insertModeKeyBindingsNonRecursive": [
          {
             "before": [
                "j",
                "k"
             ],
             "commands": [
                "cursorLineEnd",
             ]
          }
       ]
    

    My suggestion for you now is to avoid Ctrl remappings, use <leader> instead. You can also properly organize these findings and open a new issue on GitHub.

    P.S

    You can check command names in File -> Preferences -> Keyboard Shortcuts:

    enter image description here