Welcome to Vifm Q&A, where you can ask questions about using Vifm. Registration is optional, anonymous posts are moderated. E-mail and GitHub logins are enabled.
0 votes
ago in vifm by
edited ago by

I have set the below name filters in "vifmrc" file:

windo filter! /(lost\+found|Desktop|\.pyo$|\.pyc$|xxxxx)/

And in dayly operation, sometimes I set some new manual/auto name filters by running ":filter" command or "zf" command. But when I use "zO" command to remove the name filters, it also removes all the filters set in "vifmrc".

I wonder if there is any way to remove the name filters excluding the one set in "vifmrc" file?

If it has to code to achieve it, could you please help give some hint which function I should adapt, many thanks.

1 Answer

0 votes
ago by
 
Best answer

windo filter! /(lost\+found|Desktop|\.pyo$|\.pyc$|xxxxx)/

You don't need :windo in vifmrc. It's implicit there for :set and :filter since v0.8.1 (released in 2016).

I wonder if there is any way to remove the name filters excluding the one set in "vifmrc" file?

That's basically two halves of the same filter that cannot be controlled independently and I can't think of a workaround that would work.

If it has to code to achieve it, could you please help give some hint which function I should adapt, many thanks.

You want to look at this range. Something like this may do:

  1. Add new prev_*_filter fields to view_t (can be freed here; will be zero-initialized without new code).
  2. Before name_filters_drop(view);: if new fields are NULL, save state in them.
  3. After name_filters_drop(view);: restore the state from new fields.

This way zO and anything similar should always reset to the state set in configuration. You can add the new code around name_filters_remove(curr_view); here to not affect anything but zO.

ago by

Thank you, I followed your suggestions as below:
1. add "prev_config_filter" in "ui.h", and init in filelist.c
2. in "vifm.c" after vifm initial finished, store the manual name filters set in vifmrc:
replace_string(&curr_view->prev_config_filter, matcher_get_expr(curr_view->manual_filter));
3. then in "name_filters_remove", add the below line after "name_filters_drop" to restore the name filters set in vifmrc:
replace_matcher(&view->manual_filter, view->prev_config_filter);

with the above change, after I run :filter to add new name filter, then run "zO", the newly added filter is removed, and the filter set in vifmrc persists as expected.

By the way, I have another question which needs your help:
when I run :filter command to filter some files, the initial filters set in "vifmrc" are all removed. This is not related with the above "prev_config_filter" change. It seems the rule that if new name filter is added, the old other filters will be removed.

Is there any easy way to persist the filters set in "vifmrc" when adding new filters by running :filter command.

Thanks a lot for taking your time.

ago by

It seems the rule that if new name filter is added, the old other filters will be removed.

Yes, :filter doesn't add a new filter, it replaces the old one. Making filter editable was discussed at some point, but hasn't been implemented. The closest thing is Ctrl-X m which inserts current value of the filter on the command line so you can mix it with a new one, for example:

nnoremap <silent> - :filter /<c-x>m|/<left>

Is there any easy way to persist the filters set in "vifmrc" when adding new filters by running :filter command.

Similarly to the above, you could combine prev_config_filter with the new value assuming both are regular expressions, like:

char *value = format_str("(%s)|(%s)", view->prev_config_filter, filter);

Likely at this spot.

ago by

Thanks a lot for sharing these two valuable suggestions, I will try them when available.

...