question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Arrow key bindings not working with insertModeKeyBindings

See original GitHub issue

Describe the bug

The configuration for navigation with arrow keys across word wrapped lines from https://github.com/VSCodeVim/Vim/issues/2403#issuecomment-384317608 no longer works.

Bonus: The configuration does work with a separate, unrelated configuration.

To Reproduce Steps to reproduce the behavior:

  1. Install the plugin
  2. Enable word wrapping ("editor.wordWrap": "on")
  3. Configure using the config in broken.json below
  4. Notice that the <kbd>up</kbd> and <kbd>down</kbd> keys skip text past the wrap on word wrapped lines (notice that both ctrl+o and <C-o> do not work)
  5. Bonus: Configure using the config in working.json below
  6. Bonus: Notice that the <kbd>up</kbd> and <kbd>down</kbd> keys navigate to every line, even text on word wrapped lines.

broken.json

{
  "vim.insertModeKeyBindings": [
    {
      "before": [
        "down",
      ],
      "after": [
        "<C-o>",
        "g",
        "j"
      ]
    },
    {
      "before": [
        "up"
      ],
      "after": [
        "ctrl+o",
        "g",
        "k"
      ]
    }
  ]
}

working.json

{
  "vim.insertModeKeyBindings": [
    {
      "before": [
        "j"
      ],
      "after": [
        "<Esc>"
      ]
    },
    {
      "before": [
        "down"
      ],
      "after": [
        "<C-o>",
        "g",
        "j"
      ]
    },
    {
      "before": [
        "up"
      ],
      "after": [
        "ctrl+o",
        "g",
        "k"
      ]
    }
  ]
}

Expected behavior

The configuration should work in both cases (not only with the extra <kbd>j</kbd> => <kbd>Esc</kbd> configuration key).

Logs

Broken:

Code.app/Contents/Resources/app/out/vs/workbench/workbench.main.js:270 [Extension Host] debug: Extension: activating vscodevim.
/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/workbench.main.js:270 [Extension Host] debug: Extension: registering event handlers.
/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/workbench.main.js:270 [Extension Host] debug: ModeHandler: handling key=<ExtensionEnable>.
console.ts:136 [Extension Host] debug: ModeHandler: handling key=i.
2console.ts:136 [Extension Host] debug: ModeHandler: handling key=<up>.
console.ts:136 [Extension Host] debug: Remapper: insertModeKeyBindings. before=<down>. after=<C-o>,g,j. 
console.ts:136 [Extension Host] debug: Remapper: insertModeKeyBindings. before=<up>. after=<C-o>,g,k. 
2console.ts:136 [Extension Host] debug: ModeHandler: handling key=<up>.
console.ts:136 [Extension Host] debug: Remapper: insertModeKeyBindings. before=<down>. after=<C-o>,g,j. 
console.ts:136 [Extension Host] debug: Remapper: insertModeKeyBindings. before=<up>. after=<C-o>,g,k. 
console.ts:136 [Extension Host] debug: ModeHandler: handling key=<up>.
console.ts:136 [Extension Host] debug: Remapper: insertModeKeyBindings. before=<down>. after=<C-o>,g,j. 
console.ts:136 [Extension Host] debug: Remapper: insertModeKeyBindings. before=<up>. after=<C-o>,g,k. 
console.ts:136 [Extension Host] debug: ModeHandler: handling key=<up>.
console.ts:136 [Extension Host] debug: Remapper: insertModeKeyBindings. before=<down>. after=<C-o>,g,j. 
console.ts:136 [Extension Host] debug: Remapper: insertModeKeyBindings. before=<up>. after=<C-o>,g,k. 
2console.ts:136 [Extension Host] debug: ModeHandler: handling key=<up>.
console.ts:136 [Extension Host] debug: Remapper: insertModeKeyBindings. before=<down>. after=<C-o>,g,j. 
console.ts:136 [Extension Host] debug: Remapper: insertModeKeyBindings. before=<up>. after=<C-o>,g,k. 
console.ts:136 [Extension Host] debug: ModeHandler: handling key=<down>.
console.ts:136 [Extension Host] debug: Remapper: insertModeKeyBindings. before=<down>. after=<C-o>,g,j. 
console.ts:136 [Extension Host] debug: Remapper: insertModeKeyBindings. before=<up>. after=<C-o>,g,k. 
console.ts:136 [Extension Host] debug: ModeHandler: handling key=<down>.
console.ts:136 [Extension Host] debug: Remapper: insertModeKeyBindings. before=<down>. after=<C-o>,g,j. 
console.ts:136 [Extension Host] debug: Remapper: insertModeKeyBindings. before=<up>. after=<C-o>,g,k. 

Working:

Code.app/Contents/Resources/app/out/vs/workbench/workbench.main.js:270 [Extension Host] debug: Extension: activating vscodevim.
/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/workbench.main.js:270 [Extension Host] debug: Extension: registering event handlers.
/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/workbench.main.js:270 [Extension Host] debug: ModeHandler: handling key=<ExtensionEnable>.
shell.ts:482 [Violation] 'resize' handler took 196ms
[Violation] Forced reflow while executing JavaScript took 37ms
console.ts:136 [Extension Host] debug: ModeHandler: handling key=i.
console.ts:136 [Extension Host] debug: ModeHandler: handling key=<down>.
console.ts:136 [Extension Host] debug: Remapper: insertModeKeyBindings. before=j. after=<Esc>. 
console.ts:136 [Extension Host] debug: Remapper: insertModeKeyBindings. before=<down>. after=<C-o>,g,j. 
console.ts:136 [Extension Host] debug: Remapper: insertModeKeyBindings. before=<up>. after=<C-o>,g,k. 
console.ts:136 [Extension Host] debug: Remapper: insertModeKeyBindings. match found. before=<down>. after=<C-o>,g,j. command=undefined.
console.ts:136 [Extension Host] debug: ModeHandler: handling key=<C-o>.
console.ts:136 [Extension Host] debug: Remapper: insertModeKeyBindings. before=j. after=<Esc>. 
console.ts:136 [Extension Host] debug: Remapper: insertModeKeyBindings. before=<down>. after=<C-o>,g,j. 
console.ts:136 [Extension Host] debug: Remapper: insertModeKeyBindings. before=<up>. after=<C-o>,g,k. 
console.ts:136 [Extension Host] debug: ModeHandler: handling key=g.
console.ts:136 [Extension Host] debug: ModeHandler: handling key=j.
console.ts:136 [Extension Host] debug: ModeHandler: handling key=<down>.
console.ts:136 [Extension Host] debug: Remapper: insertModeKeyBindings. before=j. after=<Esc>. 
console.ts:136 [Extension Host] debug: Remapper: insertModeKeyBindings. before=<down>. after=<C-o>,g,j. 
console.ts:136 [Extension Host] debug: Remapper: insertModeKeyBindings. before=<up>. after=<C-o>,g,k. 
console.ts:136 [Extension Host] debug: Remapper: insertModeKeyBindings. match found. before=<down>. after=<C-o>,g,j. command=undefined.
console.ts:136 [Extension Host] debug: ModeHandler: handling key=<C-o>.
console.ts:136 [Extension Host] debug: Remapper: insertModeKeyBindings. before=j. after=<Esc>. 
console.ts:136 [Extension Host] debug: Remapper: insertModeKeyBindings. before=<down>. after=<C-o>,g,j. 
console.ts:136 [Extension Host] debug: Remapper: insertModeKeyBindings. before=<up>. after=<C-o>,g,k. 
console.ts:136 [Extension Host] debug: ModeHandler: handling key=g.
console.ts:136 [Extension Host] debug: ModeHandler: handling key=j.
wordHighlighter.ts:300 [Violation] 'setTimeout' handler took 82ms
mouseHandler.ts:94 [Violation] Handling of 'mousewheel' input event was delayed for 122 ms due to main thread being busy. Consider marking event handler as 'passive' to make the page more responsive.
[Violation] 'setTimeout' handler took 62ms
console.ts:136 [Extension Host] debug: ModeHandler: handling key=<up>.
console.ts:136 [Extension Host] debug: Remapper: insertModeKeyBindings. before=j. after=<Esc>. 
console.ts:136 [Extension Host] debug: Remapper: insertModeKeyBindings. before=<down>. after=<C-o>,g,j. 
console.ts:136 [Extension Host] debug: Remapper: insertModeKeyBindings. before=<up>. after=<C-o>,g,k. 
console.ts:136 [Extension Host] debug: Remapper: insertModeKeyBindings. match found. before=<up>. after=<C-o>,g,k. command=undefined.
console.ts:136 [Extension Host] debug: ModeHandler: handling key=<C-o>.
console.ts:136 [Extension Host] debug: ModeHandler: handling key=g.
console.ts:136 [Extension Host] debug: ModeHandler: handling key=k.

Environment (please complete the following information):

  • Extension Name: vim
  • Extension Version: 0.15.7
  • OS Version: Darwin x64 17.7.0
  • VSCode version: 1.25.1

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:10 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
jpooncommented, Jan 31, 2019

I fixed a couple of issues with the remapper (https://github.com/VSCodeVim/Vim/pull/3424, https://github.com/VSCodeVim/Vim/pull/3418), can you retry on the latest release (v1.0.4)? If it still doesn’t work, can you share the debug output?

1reaction
karlhorkycommented, Mar 25, 2019

I think I may have come up with a fixed version of @metasong’s keybindings (fixing the problem of escaping the autocomplete / suggest widget), based on the when condition from the extension keybindings.

It looks like this:

  {
    "key": "up",
    "command": "cursorUp",
    "when": "editorTextFocus && vim.active && !inDebugRepl && vim.mode == 'Insert' && !suggestWidgetMultipleSuggestions && !suggestWidgetVisible"
  },
  {
    "key": "down",
    "command": "cursorDown",
    "when": "editorTextFocus && vim.active && !inDebugRepl && vim.mode == 'Insert' && !suggestWidgetMultipleSuggestions && !suggestWidgetVisible"
  }

This doesn’t need any changes to settings.

I will start using this and see if there are any other problems (including performance issues) with it.

Edit: Performance is great, much better than the original method.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Arrow key bindings not firing - Stack Overflow
I copied your code and it seems to work fine. The only reason I can think for this not to work in your...
Read more >
Do you use insert mode keybindings? : r/vim - Reddit
I was helping a friend recently who was trying to make the transition to vim keybindings in spacemacs. He was asking me about...
Read more >
My Experience Using Vim Keybindings In VSCode
Then once I hit some random keys, text started showing up and I thought everything ... since I've started using Vim with VSCode...
Read more >
Fix arrow keys displaying A, B, C, D in vi (not in vim)
Sometimes such behaviour can result from unusual key mappings setup in your .vimrc - so for example if you have something that maps...
Read more >
Vim - Visual Studio Marketplace
Any key in keybindings section of the package.json that has a vim.use<C-. ... If cmd-c/ctrl-c is giving you issues, set this to false...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found