Vim icon indicating copy to clipboard operation
Vim copied to clipboard

Escape keybind conflict in notebook

Open xsrvmy opened this issue 3 years ago • 5 comments

In notebook mode there is a conflict between the escape keybind when waiting for the second key of vim commands. For example, typing d<esc> will trigger vscode's own escape function, instead of cancelling the d command. Further, vim mode is stuck waiting for the d command to complete in this case. I usually end up hitting escape to get of this mess.

Hitting escape in insert mode does work properly.

xsrvmy avatar Jan 25 '22 07:01 xsrvmy

Hello,

It is possible to remap keys in VSCode's keybindings editor and search for the Escape key in particular. From there you can unbind the conflicting keybinds or change the when clauses.

w-cantin avatar Jan 25 '22 19:01 w-cantin

Can when clause catch an incomplete vim command? Anyways I thought vscodevim added a rule already to avoid the conflict in insert mode so it's just incomplete at this point.

xsrvmy avatar Jan 25 '22 20:01 xsrvmy

The Notebook: Stop Editing Cell Escape key keybind could probably be unmapped with no ill effects. If the behaviour is absolutely necessary maybe adding an alternative keymapping for it could work too. Something like:

     {
       "before": ["leader", "esc"],
       "after": ["notebook.cell.quitEdit"]
     }

When clauses can also catch vim modes: (see the documentation). OperatorPendingMode is probably the one you are interested in.

w-cantin avatar Jan 25 '22 20:01 w-cantin

The Notebook: Stop Editing Cell Escape key keybind could probably be unmapped with no ill effects. If the behaviour is absolutely necessary maybe adding an alternative keymapping for it could work too. Something like:

     {
       "before": ["leader", "esc"],
       "after": ["notebook.cell.quitEdit"]
     }

When clauses can also catch vim modes: (see the documentation). OperatorPendingMode is probably the one you are interested in.

In my settings there is already a vim.mode == 'Normal' for the escape keybinding for escaping edit mode in a notebook but this does not seem to work with OperatingPendingMode on my computer (escape works as expected with visual and insert mode). In fact, typing y in normal mode does not show OperatingPendingMode in the status bar.

I also tried adding !(vim.mode=='OperatingPendingMode') and !(vim.mode!=='OperatingPendingMode') but that did not work. Do you see OperatingPendingMode in the status bar when you type y in normal mode ?

userrand avatar Jun 05 '23 02:06 userrand

Specifying each operator prefix in a regex — && !(vim.command =~ /^[dcygvz><!=]/) — seems to work.

  // This keybinding activates in Vim Normal mode, but only when vim.command
  // does not start with common operators. The regex excludes commands starting
  // with d, c, y, g, v, z, >, <, =, or !. This allows the shortcut to work for
  // other commands while avoiding conflict with standard Vim operations.
  // https://github.com/VSCodeVim/Vim/issues/7425
  {
    "key": "escape",
    "command": "notebook.cell.quitEdit",
    "when": "inputFocus && notebookEditorFocused && vim.active && !editorHasSelection && !editorHoverVisible && vim.mode == 'Normal' && !(vim.command =~ /^[dcygvz><!=]/)"
  },
  {
    "key": "escape",
    "command": "-notebook.cell.quitEdit",
    "when": "inputFocus && notebookEditorFocused && vim.active && !editorHasSelection && !editorHoverVisible && vim.mode == 'Normal'"
  }

edit: but possibly typing c esc very quickly in sequence still exits the cell rather than returns to Normal mode? Here's the PR for the vim.command https://github.com/VSCodeVim/Vim/pull/8718 — anyone have any ideas why the speed of the chord changes behavior?


When clauses can also catch vim modes: (see the documentation). OperatorPendingMode is probably the one you are interested in.

Does OperatorPendingMode ever get set? I can't ever get it to show in Developer: Inspect Context Keys. I see there's a comment in the code about it https://github.com/VSCodeVim/Vim/blob/2cb95520f10f0b7fe439f4f3d97a9c7f214b3416/src/mode/mode.ts#L16.


[removed previous solution of vim.command == '']

max-sixty avatar Sep 08 '24 19:09 max-sixty