Inaccurate vim emulation in marker placement when using insert-mode remappings
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 15.2k
- Forks
- 1.5k
- Avg merge
- 3d 18h
- Merged PRs (30d)
- 6
Description
Describe the bug
Making a remap that creates a marker whenever exiting insert mode leads to incorrect marker placement.
To Reproduce
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
And equivalently, you can create an equivalent mapping in VSCode with the following settings.json file:
{
"vim.insertModeKeyBindings": [
{"before": ["<esc>"], "after": ["<esc>", "m", "f"]},
]
}
This shortens the command sequence:
before: gg$ciw<esc>mfjyiw`fp
after: gg$ciw<esc>jyiw`fp
Unfortunately, this remapping only works in vim, revealing a bug in VSCode's vim emulation of marker placement.
Expected Behavior
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. In general, it appears that the difference in characters before and after insert mode determines how displaced the marker will be.
It would be nice if this were fixed, or if a hack existed to correct the behavior.
Environment (please complete the following information):
- Extension (VsCodeVim) version: 1.25.2
- VS Code Version: Code 1.81.1 (Universal) (6c3e3dba23e8fadc360aed75ce363ba185c49794, 2023-08-09T22:20:33.924Z)
- OS Version: Darwin arm64 22.5.0
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue using the insert-mode remapping in settings.json and the shortened command sequence described above. Trace how marker placement is updated after the change operation, and consider the work complete when the marker remains at the same logical location and the example produces the expected file contents.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript, vim, vscode
- Domain
- developer-experience, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 38/100