Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot remap <C-e> in insert mode #3221

Closed
sobjornstad opened this issue Nov 26, 2018 · 18 comments
Closed

Cannot remap <C-e> in insert mode #3221

sobjornstad opened this issue Nov 26, 2018 · 18 comments

Comments

@sobjornstad
Copy link

sobjornstad commented Nov 26, 2018

Describe the bug
The following setting has no effect:

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

(I don't actually want it to remap to just <esc>, but I'm starting simple.)

To Reproduce
Add the above text to settings.json and save. Enter insert mode and try pressing C-e. The character on the line below the current one is copied in -- rather than performing the mapped action of <esc>.

Expected behavior
VSCodeVim acts as if Escape was pressed.

Environment (please complete the following information):

  • Extension (VsCodeVim) version: 0.16.12
  • VSCode version: 1.29.1
  • OS: Windows 10.0.15063

Additional context
This does not appear to be a duplicate of Unable to remap <C-s> in insert mode. In that issue, the keys that people were trying to remap were not handled by VSCodeVim. In this case, <C-e> is listed in packages.json, and VSCodeVim is doing something with the key (copying the character below the cursor).

@janhesters
Copy link

janhesters commented Dec 24, 2018

Same behavior. I tried to remap:

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

Apparently there is trouble with remapping ctrl commands in general.

See here for the parent issue.
See here for a possible workaround.

@sobjornstad
Copy link
Author

The workaround is good, but it doesn't help in my case, as I use Ctrl-E to scroll in normal mode without moving the cursor, and not having that is much more annoying than not being able to bind it in insert mode. The keybindings.json is not aware of VSCodeVim's modes, so I can't override only in insert mode.

I am not sure that the parent issue @janhesters listed applies to the behavior for C-e in particular.. Maybe I'm misunderstanding, but the package.json file appears to be binding to Ctrl-E, and VSCodeVim is able to do things specific to the extension when I press Ctrl-E, so this seems like it may be a different issue.

@jpoon
Copy link
Member

jpoon commented Jan 30, 2019

Dupe of #3221

@sobjornstad
Copy link
Author

sobjornstad commented Jan 31, 2019

@jpoon: You marked this as a duplicate of itself -- did you make a typo? I'd like to follow the other issue.

@jpoon
Copy link
Member

jpoon commented Jan 31, 2019

Oh crap. I'm on mobile. There's a PR that I just submitted and merged that fixed this issue. You can find the duplicate issue from there.

Edit: dupe of #3126

@sobjornstad
Copy link
Author

Updated to 1.0.5 this morning and this is still not working for me. Or rather, it's working very inconsistently -- sometimes it works. I've only gotten it to work directly in the User Settings window and not in any other editor, even after reloading the window, and sometimes it just does nothing or copies the character on the line below (as it did before the change).

Also, if I literally type <C-e> in insert mode as the five characters, the mapping activates. >__<

I tried adding C-e explicitly to vim.handleKeys; doesn't matter whether I have it in there or not.

Here's my whole settings.json in case there's something additional in there that's interacting:

{
    "window.zoomLevel": 1,
    "editor.acceptSuggestionOnEnter": "off",
    "breadcrumbs.enabled": true,
    "files.trimTrailingWhitespace": true,
    "tfvc.location": "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Enterprise\\Common7\\IDE\\CommonExtensions\\Microsoft\\TeamFoundation\\Team Explorer\\TF.exe",
    "team.showWelcomeMessage": false,

    "vim.hlsearch": true,
    "vim.normalModeKeyBindingsNonRecursive": [
        {
            "before": [" "],
            "commands": [
                ":nohlsearch"
            ]
        },
        {
            "before": ["\\"],
            "after": [";"]
        },
        {
            "before": ["|"],
            "after": [","]
        },
        {
            "before": [";"],
            "after": [":"]
        },
    ],
    "vim.insertModeKeyBindingsNonRecursive": [
        {
            "before": ["<C-e>"],
            "after": ["<ESC>"]
        }
    ],

    "vim.handleKeys": {
        "<C-t>": false,
        "<C-j>": false,
        "<C-k>": false,
        "<C-s>": false,
        "<C-e>": true
    },

    "editor.rulers": [80],

    "[powershell]": {
        "editor.rulers": [
            120
        ]
    },

    "[markdown]": {
        "files.trimTrailingWhitespace": false
    },
    "workbench.activityBar.visible": true,
    "gitlens.currentLine.enabled": false,
    "gitlens.hovers.currentLine.over": "line",
    "editor.minimap.enabled": false,
    "workbench.sideBar.location": "right",
    "terminal.integrated.rendererType": "dom",
    "editor.renderControlCharacters": false,
    "editor.renderWhitespace": "all",
    "editor.fontLigatures": true,
    "editor.fontFamily": "'Fira Code Regular', Consolas, 'Courier New', monospace"
}

@jpoon
Copy link
Member

jpoon commented Jan 31, 2019

Can you share your console logs?

@jpoon jpoon reopened this Jan 31, 2019
@jpoon
Copy link
Member

jpoon commented Jan 31, 2019

This works consistently for me.

    "vim.insertModeKeyBindings": [
      {
        "before": [
          "<C-e>",
        ],
        "after": [
          "<esc>"
        ]
      }
    ],

similarly for insertModeKeyBindingsRecursive.

@jpoon
Copy link
Member

jpoon commented Feb 1, 2019

We even have a test case testing this exact scenario :/

https://github.com/VSCodeVim/Vim/blob/master/test/configuration/remapper.test.ts#L304

@jpoon jpoon closed this as completed Feb 1, 2019
@sobjornstad
Copy link
Author

I mapped it non-recursively, unlike your snippet or test case -- possible that has anything to do with it?

I'll take a closer look on Monday if that isn't it.

@sobjornstad
Copy link
Author

sobjornstad commented Feb 4, 2019

This morning I updated to 1.0.7, removed all VSCodeVim settings from my settings.json, pasted in your snippet, and disabled all other extensions, and it still isn't working consistently for me. I got it to work a couple times, but the rest of the time it followed its unremapped behavior (copies the character on the line below the cursor, or does nothing when there's no character below the cursor). I have not been able to find any consistent pattern (have thought it maybe had to do with my nonstandard keyboard layout, using undo, and reloading the window, but none of those seem to have a 1:1 correlation with working/not working).

I'm not sure where to get the console logs you're talking about.

@jpoon
Copy link
Member

jpoon commented Feb 4, 2019

@sobjornstad
Copy link
Author

useCtrlKeys was not explicitly set; I changed it to true and didn't see any change.

The debug logs appear to reveal that there's a timing issue. In both of these cases I'm pressing i and then <c-e>. Here's when it works:

[Extension Host] ModeHandler: debug: handling key=i.
console.ts:134 [Extension Host] Remapper: debug: trying to find matching remap. keys=i. mode=Normal. keybindings=normalModeKeyBindingsMap.
console.ts:134 [Extension Host] Remapper: debug: trying to find matching remap. keys=i. mode=Normal. keybindings=normalModeKeyBindingsNonRecursiveMap.
console.ts:134 [Extension Host] Remapper: verbose: key=i. keySlice=i.
console.ts:134 [Extension Host] ModeHandler: debug: handling key=<C-e>.
console.ts:134 [Extension Host] Remapper: debug: trying to find matching remap. keys=<C-e>. mode=Insert. keybindings=insertModeKeyBindingsMap.
console.ts:134 [Extension Host] Remapper: verbose: key=<C-e>. keySlice=<C-e>.
console.ts:134 [Extension Host] Remapper: debug: insertModeKeyBindingsMap. match found. before=<C-e>. after=<Esc>. command=undefined.
console.ts:134 [Extension Host] ModeHandler: debug: handling key=<Esc>.
console.ts:134 [Extension Host] Remapper: debug: trying to find matching remap. keys=<Esc>. mode=Insert. keybindings=insertModeKeyBindingsMap.
console.ts:134 [Extension Host] Remapper: verbose: key=<Esc>. keySlice=<Esc>.
console.ts:134 [Extension Host] Remapper: debug: trying to find matching remap. keys=<Esc>. mode=Insert. keybindings=insertModeKeyBindingsNonRecursiveMap.

And here's where it doesn't:

[Extension Host] ModeHandler: debug: handling key=i.
console.ts:134 [Extension Host] Remapper: debug: trying to find matching remap. keys=i. mode=Normal. keybindings=normalModeKeyBindingsMap.
console.ts:134 [Extension Host] Remapper: debug: trying to find matching remap. keys=i. mode=Normal. keybindings=normalModeKeyBindingsNonRecursiveMap.
console.ts:134 [Extension Host] Remapper: verbose: key=i. keySlice=i.
console.ts:134 [Extension Host] ModeHandler: debug: handling key=<C-e>.
console.ts:134 [Extension Host] Remapper: debug: trying to find matching remap. keys=i,<C-e>. mode=Insert. keybindings=insertModeKeyBindingsMap.
console.ts:134 [Extension Host] Remapper: verbose: key=i,<C-e>. keySlice=i<C-e>.
console.ts:134 [Extension Host] Remapper: debug: trying to find matching remap. keys=i,<C-e>. mode=Insert. keybindings=insertModeKeyBindingsNonRecursiveMap.

Now that I've looked at those, I can confirm that if I wait a second or so after my last keystroke in insert mode, <C-e> works correctly every time. Otherwise, VSCodeVim appears to be trying to match multiple characters and not checking to see if smaller numbers of characters form valid mappings.

@sobjornstad
Copy link
Author

Any news on this? Just want to make sure you haven't forgotten about it since the status is still "closed".

@insidewhy
Copy link
Contributor

insidewhy commented Mar 1, 2019

I'm hitting this issue also, it's very annoying but not quite as annoying as #3530 which I strongly suspect has the same cause as this.

@peitalin
Copy link

peitalin commented Apr 15, 2019

I'm seeing this issue as well:

Also, if I literally type <C-e> in insert mode as the five characters, the mapping activates. >__<

I tried adding C-e explicitly to vim.handleKeys; doesn't matter whether I have it in there or not.

With these settings, ctrl+e doesn't trigger cursorEnd, but it does trigger when I type <C-e> in insert mode. The <C-e> command does however work in normal mode fine when pressing ctrl+e.

    "vim.useCtrlKeys": true,
    "vim.handleKeys": {
        "<C-a>": true,
        "<C-e>": true,
    },
    "vim.insertModeKeyBindings": [
        {
            "before": ["<C-e>"],
            "commands": [
                {
                    "command": "cursorEnd",
                }
            ]
        }
    ],
    ...

@jpoon
Copy link
Member

jpoon commented Apr 15, 2019

Good place to debug the code is here if anybody wants to take a stab at it.

public async sendKey(

@sobjornstad
Copy link
Author

sobjornstad commented Dec 5, 2019

I am still getting the same behavior I reported originally. VSCodeVim 1.11.3 and VSCode 1.40.2 now. I tried using both NonRecursive and normal mappings.

The current debug logs when I press i, then <C-e> follow:

When it doesn't work (I press them immediately in sequence):

[Extension Host] ModeHandler: debug: handling key=i.
workbench.desktop.main.js:sourcemap:250 [Extension Host] Remapper: debug: trying to find matching remap. keys=i. mode=Normal. keybindings=normalModeKeyBindingsMap.
workbench.desktop.main.js:sourcemap:250 [Extension Host] Remapper: debug: trying to find matching remap. keys=i. mode=Normal. keybindings=normalModeKeyBindingsNonRecursiveMap.
workbench.desktop.main.js:sourcemap:250 [Extension Host] Remapper: verbose: key=i. keySlice=i.
workbench.desktop.main.js:sourcemap:250 [Extension Host] ModeHandler: debug: handling key=<C-e>.
workbench.desktop.main.js:sourcemap:250 [Extension Host] Remapper: debug: trying to find matching remap. keys=i,<C-e>. mode=Insert. keybindings=insertModeKeyBindingsMap.
workbench.desktop.main.js:sourcemap:250 [Extension Host] Remapper: debug: trying to find matching remap. keys=i,<C-e>. mode=Insert. keybindings=insertModeKeyBindingsNonRecursiveMap.
workbench.desktop.main.js:sourcemap:250 [Extension Host] Remapper: verbose: key=i,<C-e>. keySlice=i<C-e>.

When it does work (I wait a second in between presses):

[Extension Host] ModeHandler: debug: handling key=i.
workbench.desktop.main.js:sourcemap:250 [Extension Host] Remapper: debug: trying to find matching remap. keys=i. mode=Normal. keybindings=normalModeKeyBindingsMap.
workbench.desktop.main.js:sourcemap:250 [Extension Host] Remapper: debug: trying to find matching remap. keys=i. mode=Normal. keybindings=normalModeKeyBindingsNonRecursiveMap.
workbench.desktop.main.js:sourcemap:250 [Extension Host] Remapper: verbose: key=i. keySlice=i.
[Here I pause]
workbench.desktop.main.js:sourcemap:250 [Extension Host] ModeHandler: debug: handling key=<C-e>.
workbench.desktop.main.js:sourcemap:250 [Extension Host] Remapper: debug: trying to find matching remap. keys=<C-e>. mode=Insert. keybindings=insertModeKeyBindingsMap.
workbench.desktop.main.js:sourcemap:250 [Extension Host] Remapper: debug: trying to find matching remap. keys=<C-e>. mode=Insert. keybindings=insertModeKeyBindingsNonRecursiveMap.
workbench.desktop.main.js:sourcemap:250 [Extension Host] Remapper: verbose: key=<C-e>. keySlice=<C-e>.
workbench.desktop.main.js:sourcemap:250 [Extension Host] Remapper: debug: insertModeKeyBindingsNonRecursiveMap. match found. before=<C-e>. after=<C-o>,$. command=undefined.
workbench.desktop.main.js:sourcemap:250 [Extension Host] ModeHandler: debug: handling key=<C-o>.
workbench.desktop.main.js:sourcemap:250 [Extension Host] ModeHandler: debug: handling key=$.

(Edit: Just realized here I remapped C-e to C-o $ rather than to Escape as in the initial example. It behaves the same whether I remap to Escape or to this.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants