Vim Mode - Visual Selection Inconsistencies
Check for existing issues
- [X] Completed
Describe the bug / provide steps to reproduce it
Vim-Mode Visual Selection Misbehaviors
When activating the V (line) visual selection in Vim mode, the selection behaves weirdly:
First Problem
The beginning of the selection, may, in some configurations, select also the first line.
Here is a difference in behavior depending, it seems, on the content/absence of content of the last line:
https://github.com/zed-industries/zed/assets/5413308/0a46b650-0b28-45cc-b323-747719e301f8
https://github.com/zed-industries/zed/assets/5413308/bd1ca745-ce6b-4626-baf5-0d0e829f6be1
Second Problem
The last character is not part of the visual selection, unlike vim:
https://github.com/zed-industries/zed/assets/5413308/43488fec-7046-461e-9fc4-8679e8a984d1
https://github.com/zed-industries/zed/assets/5413308/584288c7-f928-48e0-a41e-0639af10c08c
Environment
Zed: v0.119.19 (Zed) OS: macOS 14.3.0 Memory: 8 GiB Architecture: aarch64
If applicable, add mockups / screenshots to help explain present your vision of the feature
No response
If applicable, attach your ~/Library/Logs/Zed/Zed.log file to this issue.
If you only need the most recent lines, you can run the zed: open log command palette action to see the last 1000.
No response
Third Problem
Given the following buffer with only 6 empty lines:
Visual Selection is blocked on line 4, I cannot go on the line under.
https://github.com/zed-industries/zed/assets/5413308/d42c016d-2f10-4537-9f3f-1a68dbff8ddd
Fourth Problem
When a visual selection is made on line 5, the cursor moves automatically on line 6:
https://github.com/zed-industries/zed/assets/5413308/1f9b78c8-75a9-42ac-8465-df40e081743a
And when a visual selection is made on line 6, the selection jumps to line 5:
https://github.com/zed-industries/zed/assets/5413308/b85ea9bf-0398-4673-876e-6d6e42941f11
@titouandk Thanks for the report! If you'd like to dive in with me to debug and fix, feel free to find time: https://calendly.com/conradirwin/pairing.
There's a bit of an impedance mismatch between zed and vim because of how line endings are represented internally:
Problems 1 and 3 seem solvable without major changes (we just need to account for these cases when moving the cursor).
Problems 2 and 4 are trickier. Vim can represent a selection including a trailing newline in two ways: your cursor is "at the end of the line", or your cursor is "at the start of an empty line".
In reality these are both "the same" point in the file: "test\n|\n"
Zed currently cannot (yet?!) distinguish the two, and we have to guess the intent (incorrectly in these cases). That said, we do have a few ways we could try and stash the metadata onto the selection object, so it doesn't seem completely unsolvable.
@ConradIrwin Very interesting, thanks for this explanation 👍
I unfortunately do not know Rust :(
@ConradIrwin I noticed another issue connected to the way line endings are represented: I use a lot of
- Shift+V (line select)
- $ (end of line, usually where the opening bracket is)
- % (go to the closing bracket)
to select blocks delimited by (), [] or {}.
With Zed, after $, I am at the end of the line but the cursor seems to be one character space after, althought there is no space at the end of that line. I tried in a Go file, and the way I could do what I wanted was by doing
- Shift+V
- $
- H (or arrow left)
- %
And in a Solidity file (no language server available), the % command doesn't go to the closing bracket at all, but that's probably another problem
The selection size for blank line seems incorrect