Vim icon indicating copy to clipboard operation
Vim copied to clipboard

Dot `.` command with multi-cursor operates multiple times on first line

Open mixProtocol opened this issue 7 years ago • 4 comments

Using the dot operator (.) to repeat keystrokes in multi-cursor mode results in those keystrokes getting applied multiple times to the line of the first cursor.

To Reproduce

  1. Create 3 lines: aaa aaaa aaaaa bbb bbbb bbbbb ccc cccc ccccc

  2. Enable multiple cursors at the start of each line.

  3. Move to start of second word and prepend '123' with key strokes: w i 123 esc

  4. Move to start of the third word with keystroke: w

  5. Attempt to insert '123' with keystroke: . (period)

Expected behavior '123' would be prepended to the second word of each line with text now as: aaa 123aaaa 123aaaaa bbb 123bbbb 123bbbbb ccc 123cccc 123ccccc

Actual Results* aaa 123aaaa 121212333aaaaa bbb 123bbbb bbbbb ccc 123cccc ccccc

mixProtocol avatar Apr 19 '19 02:04 mixProtocol

.

ldm0 avatar Oct 26 '19 06:10 ldm0

@J-Fields Fixed this in feaf4adb0a98450a2a0a0dfe03556b8f70a9328b (#4778)

gergelyth avatar May 15 '20 07:05 gergelyth

An Update on this topic.

The problem is/was caused by this:

  1. Dot is done by replaying recorded keys/actions. For multicursor, this replaying is enough to execute at all cursors.
  2. Default for a command is to be executed for all cursors

If you combine 1. and 2., you see how the problem happens. The fix proposed by #4778 is this and it works.

  runsOnceForEveryCursor() {
    return false;
  }

But strictly speaking, this problem is also solved by #5025, because i did override 2. there. But I think #4778 is a better approach.

The problem that is still open is #4816, which is not solved by 5025 nor 4778. I am trying to track this down, but no success yet. An interesting fact: other operations, like backspace or pasting a register do repeat with multicursor.

edit: there are two things I tried to see, if the problem is connected to them. I think they are not.

  • transformation type insertTextVSCode vs insertText
  • compression of document changes for repeat

sql-koala avatar Feb 28 '21 11:02 sql-koala

I've seen a few issues related to multiline editing and ., some of them are marked as completed or resolved by different pull requests that have been merged, but this is still an issue (shown using v1.24.3):

3691

This kind of editing is a really useful feature of vim, so it hurts when the vs code vim bindings get it wrong!

samuelpmish avatar Jan 10 '23 18:01 samuelpmish