Skip to content

feat: add rename with substitute command#3338

Open
Uanela wants to merge 2 commits into
masterfrom
feat/rename-with-substitute
Open

feat: add rename with substitute command#3338
Uanela wants to merge 2 commits into
masterfrom
feat/rename-with-substitute

Conversation

@Uanela

@Uanela Uanela commented Jun 16, 2026

Copy link
Copy Markdown
Collaborator

Motivation #3328

I found this feature on Oil and at least for me this was/is the main reason I use Oil, the first one was visual operations like copy/delete/cut and so on, but this one was missing, basically allowing :%s/old/new to change nodes names renaming and writing to disk.

Changes

1 - Added M.bulk_rename into rename-file.lua
2 - Added opts into M.rename to prevent notifications as it is used on a loop
3 - Added opts to get_visual_nodes to correctly allow using '<,'> when needed
4 - (Not quite sure where to put yet or organize), Added an autocmd for watching ex commands

Features

1 - :%s/old/new will select or visible nodes and a simple prompt to rename (substitute) if yes they are written to disk
2 - :'<,'>s/old/new works the same way but on the visual selected part

Concerns

1 - Where and how should the new ex commands autocmd be devided?
2 - Should the autocmd of ex commands stay? or instead create at dedicated something like NvimTreeSubs or whatever to put the tree into substitution mode? - first approach is more natural and expected

I am quite sure that there is a lot of work regarding code organization here, will just wait for your suggestions.

@Uanela Uanela requested review from alex-courtis and v3ceban June 16, 2026 22:03

@v3ceban v3ceban left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I considered adding something like this in my initial implementation of bulk ops, but ended up not to due to complexities of renaming directories, nested structures, and converting files <-> dirs. If this only targets files I imagine it should be good.

It's missing the mappings to actually try it out, but the logic looks good to me. There are no regressions with existing bulk ops.

I'll leave organization questions for the core maintener to decide on.

Comment thread lua/nvim-tree/utils.lua
Comment on lines +539 to +540
local start_line = vim.fn.line(opts.use_native == true and "'<" or "v")
local end_line = vim.fn.line(opts.use_native == true and "'>" or ".")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants