This change adds the ability to increment / decrement numbers that are
part of a visual selection. Previously Zed would resolve to the entire
number under visual selection for increment as oppposed to only
incrementing the part of the number that is selected
Release Notes:
- vim: Fixed increment/decrement in visual mode
In Vim mode, `ap` text object (used in `vap`, `dap`, `cap`) was
selecting multiple paragraphs when soft wrap was enabled. The bug was
caused by using DisplayRow coordinates for arithmetic instead of buffer
row coordinates in the paragraph boundary calculation.
Fix by converting to buffer coordinates before arithmetic, then back to
display coordinates for the final result.
Closes#35085
---------
Co-authored-by: Conrad Irwin <conrad.irwin@gmail.com>
Closes#21198
Release Notes:
- Adds support for `:norm`
- Allows for vim and zed style modified keys specified in issue
- Vim style <C-w> and zed style <ctrl-w>
- Differs from vim in how multi-line is handled
- vim is sequential
- zed is combinational (with multi-cursor)
Closes#14760
Still TODO:
* Vim actually undoes *many* changes if they're all on the same line.
Release Notes:
- vim: Add `U` to return to the last changed line and undo
This Pull Request introduces various changes to the editor's horizontal
scrolling, mostly focused on vim mode's horizontal scroll motions (`z
l`, `z h`, `z shift-l`, `z shift-h`). In order to make it easier to
review, the logical changes have been split into different sections.
## Cursor Position Update
Changes introduced on https://github.com/zed-industries/zed/pull/32558
added both `z l` and `z h` to vim mode but it only scrolled the editor's
content, without changing the cursor position. This doesn't reflect the
actual behavior of those motions in vim, so these two commits tackled
that, ensuring that the cursor position is updated, only when the cursor
is on the left or right edges of the editor:
-
ea3b866a76
-
805f41a913
## Horizontal Autoscroll Fix
After introducing the cursor position update to both `z l` and `z h` it
was noted that there was a bug with using `z l`, followed by `0` and
then `z l` again, as on the second use `z l` the cursor would not be
updated. This would only happen on the first line in the editor, and it
was concluded that it was because the
`editor:📜:autoscroll::Editor.autoscroll_horizontally` method was
directly updating the scroll manager's anchor offset, instead of using
the `editor:📜:Editor.set_scroll_position_internal` method, like
is being done by the vertical autoscroll
(`editor:📜:autoscroll::Editor.autoscroll_vertically`).
This wouldn't update the scroll manager's anchor, which would still
think it was at `(0, 1)` so the cursor position would not be updated.
The changes in [this
commit](3957f02e18)
updated the horizontal autoscrolling method to also leverage
`set_scroll_position_internal`.
## Visible Column Count & Page Width Scroll Amount
The changes in
d83652c3ae
add a `visible_column_count` field to `editor:📜:ScrollManager`
struct, which allowed the introduction of the `ScrollAmount::PageWidth`
enum.
With these changes, two new actions are introduced,
`vim::normal:📜:HalfPageRight` and
`vim::normal:📜:HalfPageLeft` (in
7f344304d5),
which move the editor half page to the right and half page to the left,
as well as the cursor position, which have also been mapped to `z
shift-l` and `z shift-h`, respectively.
Closes#17219
Release Notes:
- Improved `z l` and `z h` to actually move the cursor position, similar
to vim's behavior
- Added `z shift-l` and `z shift-h` to scroll half of the page width's
to the right or to the left, respectively
---------
Co-authored-by: Conrad Irwin <conrad.irwin@gmail.com>
Closes#23527Closes#30183
Closes some Discord chats
Release Notes:
- vim: Motions now push to the jump list using the same logic as vim
(i.e.
`G`/`g g`/`g d` always do, but `j`/`k` always don't). Most non-vim
actions
(including clicking with the mouse) continue to push to the jump list
only
when they move the cursor by 10 or more lines.
Reland of #30345 to fix merge conflicts with the new skip-completions
option
Fixes#29431Fixes#17592
Release Notes:
- vim: Scrolls are no longer added to the jumplist
Closes#27998
Also fixed an issue where jumping back from closing to opening tags
didn't work in javascript due to missing brackets in our tree-sitter
query.
Release Notes:
- N/A
---------
Co-authored-by: Conrad Irwin <conrad.irwin@gmail.com>
This Pull Request fixes the current paste behavior in vim mode, when in
visual mode, and the cursor is at a newline character. Currently this
joins the pasted contents with the line right below it, but in vim this
does not happen, so these changes make it so that Zed's vim mode behaves
the same as vim for this specific case.
Closes#29270
Release Notes:
- Fixed pasting in vim's visual line mode when cursor is on a newline
character
Fixes:
`] space` does not consume counts, and it gets applied to the next
action.
`] space` on an empty line causes cursor to move to the next line.
Release Notes:
- N/A
Release Notes:
- `r enter` now maintains indentation, matching vim
Useful info for this implementation can be found here:
c3f48e3a76/src/normal.c (L4865)
## Why?
Some users expressed a preference for the AnyQuotes and AnyBrackets text
objects to align more closely with traditional Vim behavior, rather than
the mini.ai plugin's approach. To address this, I’ve introduced two new
text objects: MiniQuotes and MiniBrackets. These retain the mini.ai
plugin behavior, while the updated AnyQuotes and AnyBrackets now follow
the logic described in [this bug
report](https://github.com/zed-industries/zed/issues/25563) and [this
bug report](https://github.com/zed-industries/zed/issues/25562).
## Behavior Overview:
### AnyQuotes and AnyBrackets:
These now prioritize the innermost range first (e.g., the closest quotes
or brackets). If none are found, they fall back to searching the current
line. This aligns with the behavior requested in the issue.
### MiniQuotes and MiniBrackets:
These maintain the mini.ai plugin behavior, prioritizing the current
line before expanding the search outward.
### Usage Examples:
AnyQuotes: Works like ```ci', ci", ci` , ca', ca", ca` , etc.```
AnyBrackets: Works like ```ci(, ci[, ci{, ci<, ca(, ca[, ca{, ca<,
etc.```
Please give these changes a try and let me know your thoughts!
### Release Notes:
- vim: Add AnyQuotes, AnyBrackets, MiniQuotes and MiniBrackets text
objects
---------
Co-authored-by: Ben Kunkle <ben@zed.dev>
This Pull Request attempts to fix an issue where using `d}` in vim mode
would not delete all characters in case there's no blank lines at the
end of the buffer.
When calculating the end point for this motion, if there's no blank
lines at the end of the buffer, Zed was calculating it to be the last
character in the last line. However, if there's a newline at the end of
the buffer, it calculates the end point to be the point at the right of
the last character.
Here's an example, for the following buffer contents:
```
Hello!
Hello!
```
If the `d}` command is run at `(0, 0)`, the end point will be set to
`(1, 5)`. However, fi the same command is run for this buffer instead:
```
Hello!
Hello!
```
The end point will be set to `(1, 6)`, there's a 1 unit difference in
the column, which leads to all characters actually being deleted.
Closes#29393
Release Notes:
- Fixed deleting to the end of paragraph when there's no blank lines
---------
Co-authored-by: Conrad Irwin <conrad.irwin@gmail.com>
When using 'c' with line-wise motions like j/k, operate like cc to fix
indentation issues.
Closes#28933
Release Notes:
- `c j` and `c k` now respect indentation
I wrote the test wrongly in
https://github.com/zed-industries/zed/pull/28005:
It should be `$` instead of `shift-4`, so it was just yanking from the
middle of the line instead of the newline character. Fixed it and
regenerated it.
Release Notes:
- N/A
Problem:
When yanking in visual line on the newline char, the next line gets
yanked as well:
https://github.com/user-attachments/assets/40f332dd-19f5-445f-a30f-39d50167c46f
Changes:
Similar to visual delete, exclude the newline char from the selection in
line mode.
Release Notes:
- vim: Fixed visual line yank while on the newline character yanking
following line
Closes https://github.com/zed-industries/zed/issues/27619
Fixes issue with right wrapped movement when a multi-byte character is
at the end of the line. This is done by grabbing the last character on
the current row and using that characters size to calculate the
`max_column` variable, which is used to decide if the next right
movement should move down the line or not.
We did notice a bit of code that could be an issue that we wanted to
call out.
[Here](https://github.com/zed-industries/zed/blob/main/crates/editor/src/display_map.rs#L1070)
inside of `clip_at_line_end` it also does a saturating_sub(1), assuming
a single byte character. We didn't run into any issues due to this line
but felt like a similar bug. We can apply a similar fix if wanted to
pose the question first.
Test case: Moving to next line when eol is a multi-byte character
https://github.com/user-attachments/assets/1021ab1f-f49d-4986-8f9a-8cfc7e5c91bc
Release Notes:
- Fixed issue in vim forward spacing when a multi-byte character is at
the eol
---------
Co-authored-by: KyleBarton <kjbarton4@gmail.com>
Before this change we didn't explicitly handle vim's exclusive-linewise
edgecase
(https://neovim.io/doc/user/motion.html#exclusive).
Instead we had hard-coded workarounds in a few places to make our tests
pass.
The most pernicious of these workarounds was that we represented a
visual line
selection as including the trailing newline (or leading newline for
files that
end with no newline), which other code had to undo to get back to what
the user
indended.
Closes#21440
Updates #6900
Release Notes:
- vim: Fixed `d]}` to not delete the closing brace
- vim: Fixed `d}` from the start of the line to not delete the paragraph
separator
- vim: Fixed `d}` from the middle of the line to not delete the final
newline
Closes#27385
Builds on #27604 so that `vim::OtherEnd` works in visual block mode.
This is accomplished by reversing the order of active selections in the
buffer when the user hit `o`, so that the cursor moves diagonally across
the selection. The current behavior is preserved for `shift-o`, which is
how the cursors behave in vim.
We'll close#27604 since this encapsulates that change, but if you'd
prefer to take only the visual block motion component, we'll keep the
branch for #27604 open.
Test case: growing a box down and to the right, other ending, followed
by growing and shrinking the box:
https://github.com/user-attachments/assets/1df544e1-efce-4354-b354-bbfec007a7df
Test case: growing a box up and to the left, other ending, followed by
growing and shrinking the box:
https://github.com/user-attachments/assets/2f6d7729-c63a-4486-960b-23474c2e507a
Release Notes:
- Improved visual block mode when cursor is at beginning of selection
- Improved visual block mode so that `o` and `shift-o` reach parity with
vim
---------
Co-authored-by: KyleBarton <kjbarton4@gmail.com>
Closes#22398
Release Notes:
- vim: Adds `'` and `"` marks (last location jumped from in the current
buffer, and location when last exiting a buffer)
---------
Co-authored-by: Conrad Irwin <conrad.irwin@gmail.com>
Closes#26806
Changes: Clips the new point with `Bias::Right` like in
`saturating_right`
Release Notes:
- vim: Fixed `space` not handling non-ascii characters
Closes https://github.com/zed-industries/zed/discussions/25665
> Currently Zed is missing quite an useful Vim motion: <count>% (go to
{count} percentage in the file).
Description:
{count}% - Go to {count} percentage in the file, on the first non-blank
in the line linewise. To compute the new line number this formula is
used: ({count} * number-of-lines + 99) / 100 .
> [Link](https://neovim.io/doc/user/motion.html#N%25).
Release Notes:
- vim: Added `<count>%` motion
---------
Co-authored-by: Conrad Irwin <conrad@zed.dev>
Closes#22536
Changes:
- Visual and visual block: Cursor at start of selection.
- Visual line: Cursor at start on line.
- Uses different handling since the selection does not actually change
in vline.
Release Notes:
- vim: Fixed insert before (`shift-i`) in visual modes.
Changes:
- [x] Cursor at the start during yank operations on objects (`yip`,
`yab` etc).
- [x] Refactors this: Trim all leading and trailing whitespace from
inner multiline bracket selection.
- This leaves a nicely indented line when doing `ci{` `vi{d` etc
- [x] Checks for empty selection
- [x] Removed moving cursor to the start in visual bracket operations
This cleans up the previous implementation by providing a simpler check
in `surrounding_markers`, instead of calling a new function in
`expand_object`. No functionality was changed there except for handling
the empty selection and removing some cursor adjustments that should not
have been there after further testing.
Release Notes:
- N/A
Appears this test was failing, and someone edited the expected test
output instead of fixing it. Well no longer!
Release Notes:
- N/A
Co-authored-by: Conrad <conrad@zed.dev>
Closes#24270
Release Notes:
- Fixed an issue where doing line-wise operations in vim mode on the
last line of a file with no trailing newline would not work properly
Co-authored-by: Conrad Irwin <conrad@zed.dev>
Closes#24124
Release Notes:
- Fixed an issue in vim mode where changing the case of an object at the
end of the line would not change the case of the last character in the
object
Co-authored-by: Conrad Irwin <conrad@zed.dev>