Search and replace on filenames with space #68
Labels
No labels
autorelease: pending
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
upstream/digest
upstream/pr
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
barrettruth/canola.nvim#68
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This was something that didn't work in the original oil.nvim because files get all mangled, take a look at this issue to see what I mean: https://github.com/stevearc/oil.nvim/issues/388
I use oil.nvim as a general file manager, where I do mass renaming of files and son on. So it's annoying that I can't replace spaces in filenames with any other character like:
-or_.While taking a look at this fork, I noticed this in the README:
And according to stevearc, the problem was:
So I wonder if the issue above can be fixed.
Thank you for the well-formatted issue with appropriate context.
I'm supposing that you're on the canola branch - all following discussion assumes so.
Unfortunately, despite major architectural changes, I never actually decided to mess with the fundamental way that oil.nvim stores files in the buffer (i.e. the
/<id><space>prefix). This was simply because I was too scared (lol).I will be investigating and seeing if this is something that I can change, perhaps in light of my discovery of how vim-dirvish stores paths.
I am sorry that this was not resolved as (sort of) advertised :/ - this was marked as out-of-scope in the upstream tracker. I'll give it another shot. Note that storing filepaths in buffers like this comes with some fundamentally intractable problems - so, it's not that it solving this is impossible - it's that every solution has a tradeoff no matter what.
Thanks for your consideration.
I found a prospective solution. Unfortunately, it's literally an entire massive codebase refactor.
I need to finish my finals :/ so I will tackle this in a week.
Sorry for the hypocrisy here as advertised - I'll get on it as soon as I can,
@barrettruth You don't need to apologize for anything. I was asking out of curiosity, not with the expectation of this being "solved". Keep up with the great work, and good luck in your finals!
No but - it is something that I want to do XD. No worries - I'll @ you in the thread with a branch with the MVP implementation when done. Thanks for using canola
Just wanna share, that it's still possible to do that replacement with a little more advanced regexes. They're way less convenient (although can be easily abstracted into commands or similar), but will do the job if you find yourself having to rename plenty of files like that.
For example:
%s/^\/\d\d\d \+\zs.*/\=substitute(submatch(0), ' ', '-', 'g')In the above:
^- match from the beginning of the line\/\d\d\dmatch any/{digit}{digit}{digit}which seems to be the pattern for oil (canola) ids\+- match all the spaces after that, until something that's not a space\zs- only start the match from this position (\zs and \ze are very underappreciated, I recommend looking into them).*- match everything after (becomes match 0)then
\=- interpret the reminder as an expressionsubstitute(submatch(0), ' ', '-', 'g')- we're using vim'ssubstitutefunction as the expressionEDIT: the prev. regex didn't handle repeated spaces after id properly
To be fair @barrettruth I think a reasonable interim solution would be to provide some nice command/keybind/whatever that can be used for such renames of FILES only
Unfortunately, the regex does nothing to actually solve the problem on either canola nor main.
Also, thanks for using the plugin.
I don't understnad - can you pls elaborate on this? what would the api/"shape" look like?
Hm, you're right - there are multiple spaces there. In such a case it needs to be augmented slightly:
%s/^\/\d\d\d \+\zs.*/\=substitute(submatch(0), ' ', '-', 'g')The only addition is the
\+after the first space. This matches all the spaces between theidand the filenames, works fine for me.Well, I'm not sure - this is totally up to you and users to be fair. I do use canola, but I am not in need of such functionality. One very simple way would probably be to expose a command like
OilReplace <from> <to>,fromandtocould be as simple as literal strings or as advanced as vim/lua patterns. The command would make sure to only replace the part of buffer lines which contain the filenames (which shouldn't be terribly hard, from what I see after parsing the line, you already have a nice "type" which has thenameandidseparated)working on something rn :D
Actually, see the recent commits. I think this resolves this. If y'all have feedback on the docs or provided utility recipe, feel free to leave a comment.
#367, #368, #369
canola and main branch both updated