Skip to content

Inaccurate vim emulation in marker placement when using insert-mode remappings #190509

@ekiefl

Description

@ekiefl

Does this issue occur when all extensions are disabled?: Yes

  • VS Code Version: Code 1.81.1 (Universal) (6c3e3db, 2023-08-09T22:20:33.924Z)
  • OS Version: Darwin arm64 22.5.0

List of extensions:

Extension Author (truncated) Version
python ms- 2023.14.0
vscode-pylance ms- 2023.8.20
material-icon-theme PKi 4.29.0
vscode-sort-json ric 1.20.0
find-it-faster Tom 0.0.25
vim vsc 1.25.2

Steps to reproduce / description

I like to make a marker whenever I exit insert mode. Here's a toy example where I replace a word via this approach:

Starting with this file:

this_is_a_variable = old_name
new_name

Using the vim command sequence:

gg$ciw<esc>mfjyiw`fp

Yields the following modification to said file:

this_is_a_variable = new_name
new_name

This behavior is consistent between vim and VSCode.

In vim, you can automate making the marker f with an insert-mode remapping:

" when exiting insert mode, the marker f is made
inoremap <esc> <esc>mf

This shortens the command sequence and preserves the behavior when in vim:

before: gg$ciw<esc>mfjyiw`fp
after:  gg$ciw<esc>jyiw`fp

But making the equivalent remapping in the VSCode settings.json reveals a bug in VSCode's vim emulation. Applying the new command sequence, instead of this:

this_is_a_variable = new_name
new_name

you get this:

this_is_a_varianew_nameble = 
new_name

The marker is displaced left of it's correct location, and by an amount equal to the difference in line length before versus after the change (c) operation.

Here is the settings.json used:

{
    "vim.insertModeKeyBindings": [
        {"before": ["<esc>"], "after": ["<esc>", "m", "f"]}, // FIXME
    ]
}

It would be nice if this were fixed, or if a hack existed to correct the behavior.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions