lambdalisue / vim-fern

🌿 General purpose asynchronous tree viewer written in Pure Vim script
MIT License
1.29k stars 49 forks source link

Feature request: Add an ability to bulk / recursively mark files based on which directory node is selected #184

Closed nickjj closed 4 years ago

nickjj commented 4 years ago

The use case I'm thinking about here is if you have 500 files that you want to rename in a Vim buffer. Unless I missed something in the docs, you'd have to manually mark each of those 500 files and that would be very tedious. Let's say you were trying to re-organize how you label images or something.

This new feature I'm requesting could potentially allow you to move your cursor over a directory node, run a new action mark-all-files and it will toggle mark / unmark all files. Alternatively there could also be mark-all-files-recursive which does the same thing but it toggles marks in all files in any depth of directories.

I'll admit, I haven't thought this through in detail because what about marking directories, or a mixture of directories and files. But I think maybe the most simple / basic use case would be wanting to mark all files in a directory, with or without being recursive and if directories were ever to be considered, those could be separate actions so the file case wouldn't interfere with that API if it existed today?

What do you think?

lambdalisue commented 4 years ago

Got it. But it's a bit difficult to implement such features, especially the recursive one.

lambdalisue commented 4 years ago

@nickjj Please try the mark-children:toggle:leaf action on #192. Note that "recursive" is too complicated to implement so the PR only provides non-recursive actions. Because it's too complicated, recursive actions would never be implemented.

nickjj commented 4 years ago

That action did toggle marks on files that were included in a directory that I had selected (the root node).

I tested it by running:

mkdir -p /tmp/testfern/foo \
  && cd /tmp/testfern \
  && touch a b c d e f g h

vim .

Then ran the action you asked me to. Files a-h were toggled and the foo directory was unmarked. toggle:node did everything (including the foo directory).

In my fern config I have k set to toggle mark on individual files. I'd probably map K to do a leaf toggle. I think that works out nicely with having a distinct mapping that controls bulk behavior, as opposed to making the existing individual mark work in a bulk way if the cursor is under a directory instead of file. What do you think?

lambdalisue commented 4 years ago

In my fern config I have k set to toggle mark on individual files. I'd probably map K to do a leaf toggle. I think that works out nicely with having a distinct mapping that controls bulk behavior, as opposed to making the existing individual mark work in a bulk way if the cursor is under a directory instead of file. What do you think?

I don't get it. Fern already provides distinct mappings; <Plug>(fern-action-mark) and <Plug>(fern-action-mark-children); on #192. Did you mean that fern should NOT provide distinct mappings??? In that case, you can use fern#smart#leaf() to define combined one by yourself.

nickjj commented 4 years ago

Oh you told me to test the toggle:leaf mapping and that seemed to do what I was hoping for.

I think distinct is good because you might want to toggle a mark on a single directory without marking the children files so it seems reasonable to have 2 binds for that based on what you want to do.

lambdalisue commented 4 years ago

@nickjj Please upgrade your fern to v1.21.0 and add https://github.com/lambdalisue/fern-mapping-mark-children.vim

nickjj commented 4 years ago

Is the implementation of that plugin the same as the PR here? I may stick with the PR branch if that's the case.

lambdalisue commented 4 years ago

Is the implementation of that plugin the same as the PR here? I may stick with the PR branch if that's the case.

Then you will lose any future updates because I removed (and I'm not going to restore) that PR branch.

nickjj commented 4 years ago

I'll keep an eye on merging in updates. I just didn't want to bring in another plugin for a few lines of code.

Thanks for the feature tho, marking is something I'll be doing pretty often.