oil.nvim icon indicating copy to clipboard operation
oil.nvim copied to clipboard

feature request: Improve c0/d0 Motion for Renaming Files Instead of Deleting

Open ghost opened this issue 1 year ago • 1 comments

Did you check existing requests?

  • [x] I have searched the existing issues

Describe the feature

Issue Description

The current behavior of the c0/d0 motion in oil.nvim deletes a file entirely and creates a new one, which is unintuitive for renaming workflows.

Proposal

Make the c0/d0 motion support renaming a file instead of deleting and recreating it.

Expected Behavior

When c0 is used within the filename:

  • Transition into renaming mode (similar to a buffer edit) without deleting the file.
  • The file should only be renamed after the change is applied.

https://github.com/user-attachments/assets/0c70c239-e692-4352-bfc0-fa0358e674ed

Provide background

When renaming a file (e.g., foo.md), users often move the cursor to the file name, perhaps around the . delimiter, and use motions like c0 to change the file's name. Currently, this deletes the file instead of facilitating a rename. Changing this behavior to directly rename the file would:

  1. Align with user expectations for text-editing motions in buffers.
  2. Provide a smoother, less destructive workflow for managing files in the explorer.

What is the significance of this feature?

strongly desired

Additional details

No response

ghost avatar Jan 27 '25 20:01 ghost

This is unfortunately one of the limitations of the implementation right now. I don't particularly want to introduce some sort of hack like remapping c0/d0 because I think that's more likely to create confusion be difficult to support. The solution here is if Neovim adds support for extmarks that can be deleted and pasted. We have 2/3 of what we need with the invalidate and undo_restore parameters of nvim_buf_set_extmark, but we need some way to make it so that a deleted range with an extmark that gets pasted retains that extmark (or some data from the original). If we get that, then I can get rid of the leading ID numbers on the lines entirely and fix this edge case.

stevearc avatar Jan 27 '25 23:01 stevearc