Skip to content

vim: Add :<range>w <filename> command#41256

Merged
ConradIrwin merged 3 commits intozed-industries:mainfrom
AidanV:range
Nov 13, 2025
Merged

vim: Add :<range>w <filename> command#41256
ConradIrwin merged 3 commits intozed-industries:mainfrom
AidanV:range

Conversation

@AidanV
Copy link
Contributor

@AidanV AidanV commented Oct 27, 2025

Release Notes:

  • Adds support for :[range]w {file}
    • This writes the lines in the range to the specified
  • Adds support for :[range]w
    • This replaces the current file with the selected lines

@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Oct 27, 2025
@github-actions github-actions bot added the community champion Issues filed by our amazing community champions! 🫶 label Oct 27, 2025
@AidanV AidanV force-pushed the range branch 2 times, most recently from 1ef733b to 96d25d2 Compare October 27, 2025 05:58
@ConradIrwin
Copy link
Member

@AidanV Nice, thanks!

When overwriting the current file in vim, the buffer retains it current contents. I think we should emulate this too (so the buffer is written, but marked as dirty).

@AidanV AidanV marked this pull request as draft October 29, 2025 18:52
@AidanV AidanV marked this pull request as ready for review October 31, 2025 20:14
@AidanV
Copy link
Contributor Author

AidanV commented Oct 31, 2025

When writing to the current file we now retain the buffer contents and mark the buffer as conflicted. I also added a check to just save the file when we are selecting the entire buffer in order to match Vim.

@ConradIrwin
Copy link
Member

I don't think it should be marked conflicted? Just unsaved. What does vim do?

@AidanV
Copy link
Contributor Author

AidanV commented Nov 11, 2025

Vim does not have the concept of conflicted as far as I am aware. Vim silently has different contents in the buffer and the file.

I think that marking the buffer as conflicted provides a better UI since it informs the user that the file on disk changed without updating the buffer contents.

Additionally, marking the buffer conflicted makes it more intuitive to get at the new file contents by clicking Discard when saving. If it is just unsaved, you either have to close and reopen the file or :e. Both of these options still work when using conflicted instead of unsaved but have worse discovery IMO.

Another reason I think this is better is because writing a range of lines to its own file can be useful for Vim power users but can be very confusing for newcomers. Showing that it is conflicted improves the transparency of what is going on in a way that Vim cannot do by default.

I should have included these reasons in the PR. I will do that next time.

I will also happily change it if you still think it should be unsaved. Let me know your thoughts.

@ConradIrwin
Copy link
Member

Ok, conflicted makes sense.

That said, on 8615b38, if I open README.md and type :3,5w! README.md, then the loaded contents of the buffer becomes just lines 3-5 still?

@AidanV
Copy link
Contributor Author

AidanV commented Nov 13, 2025

In the README.md file :3,5w! README.md has the same behavior as just :3,5w!. In other words, the loaded content of the buffer is not updated but is marked as conflicted.

In Vim, :3,5w! README.md does the same thing as :3,5w!. Neither of which update the loaded buffer content but both change the file contents.

@ConradIrwin
Copy link
Member

Hmm, I'm sure when I tested this last night I was not seeing that; but trying again this morning it works as you say; sorry about that.

@ConradIrwin ConradIrwin merged commit 84f24e4 into zed-industries:main Nov 13, 2025
24 checks passed
11happy pushed a commit to 11happy/zed that referenced this pull request Dec 1, 2025
Release Notes:

- Adds support for `:[range]w {file}`
  - This writes the lines in the range to the specified
- Adds support for `:[range]w`
  - This replaces the current file with the selected lines
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement community champion Issues filed by our amazing community champions! 🫶

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants