visual-studio-codegithub-copilotvscodevim

With GitHub Copilot Next Edit Suggestions (preview), How do I Remap [Tab] and [Esc] as those Conflict with Vim?


I'm a VS Code user that uses the vscodevim extension. When also using GitHub Copilot Next Edit Suggestion (NES) feature, it requires the usage of Tab and ESC which conflict with VIM.

How can a remap the NES keys, as Tab in Normal mode does not register and ESC in Insert mode exits Insert mode?


Solution

  • Take a look this github discussion and suggestion: https://github.com/VSCodeVim/Vim/issues/9459#issuecomment-2648156285

    The code is below. The key points how it works:

    // Place your key bindings in this file to override the defaults
    [
        {
            "key": "escape",
            "command": "-extension.vim_escape",
            "when": "editorTextFocus && vim.active && !inDebugRepl"
        },
        {
            "key": "escape",
            "command": "extension.vim_escape",
            "when": "editorTextFocus && vim.active && !inDebugRepl && !testing.isPeekVisible && !testing.isInPeek && (vim.mode == 'Insert' || !notebookEditorFocused) && !inlineEditIsVisible && !suggestWidgetVisible && !findWidgetVisible && !dirtyDiffVisible"
        },
        {
            "key": "escape",
            "command": "runCommands",
            "when": "vim.mode == 'Insert' && inlineEditIsVisible",
            "args": {
                "commands": [
                    "editor.action.inlineSuggest.hide",
                    "extension.vim_escape"
                ]
            }
        },
        {
            "key": "escape",
            "command": "runCommands",
            "when": "vim.mode == 'Insert' && suggestWidgetVisible",
            "args": {
                "commands": [
                    "hideSuggestWidget",
                    "extension.vim_escape"
                ]
            }
        },
        {
            "key": "escape",
            "command": "-hideSuggestWidget",
            "when": "suggestWidgetVisible && textInputFocus"
        },
        {
            "key": "escape",
            "command": "hideSuggestWidget",
            "when": "suggestWidgetVisible && textInputFocus && !vim.active"
        },
        {
            // Remove VSCodeVim's handling of tab to enable default handling of tab
            // e.g. for inline suggestions.
            "key": "tab",
            "command": "-extension.vim_tab",
        },
    ]