2

Say I have entries like this in the quickfix window:

manage.py|7 col 54| os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'dist.plug.from.settings')
project/urls.py|29 col 6| from dist.plug.apps import PlugConfig
project/urls.py|30 col 6| from dist.plug.urls import dist_urlpatterns
project/wsgi.py|15 col 50| os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'dist.plug.from.settings')
config/cfg3_distro.py|15 col 10| from dist.plug.cfg1_custom import Custom
apps_web/csslib/cprops.py|5 col 6| from dist.plug.theme import theme
core/accounts/admin.py|10 col 6| from dist.plug.user import UserAdminMixin
core/accounts/models.py|4 col 6| from dist.plug.user import UserMixin
core/accounts/utils.py|1 col 6| from dist.plug.user import UserMixin

I wish to keep all entries that don't start with from.

:h Cfilter does not explain whether the filter matches the whole line (i.e. file name, line/col and line), or just the line. So I tried both ways but neither is working for me:

If it matches the whole line I tried:

  • :Cfilter! /| from/ matches nothing (all remain)
  • :Cfilter! /\| from/ matches everything (nothing remains)

If it matches just the line from the file, I tried:

  • :Cfilter! /^from/ matches some (some starting with from are removed, but some with from in the start remain, not sure what it did)
  • :Cfilter! /\^from/ matches nothing (all remain)

Confused as to whats going on, I must be missing something.

1
  • 1
    Good question, though in this case :Cfilter! import might be simpler
    – D. Ben Knoble
    Commented Jun 29, 2022 at 19:40

1 Answer 1

2

Instead of removing all the entries that don't start with from, use Cfilter (without !) to keep all the entries that start with from.

The |:Cfilter| command creates a new quickfix list from the entries matching {pat} in the current quickfix list. {pat} is a Vim |regular-expression| pattern. Both the file name and the text of the entries are matched against {pat}. If the optional ! is supplied, then the entries not matching {pat} are used. The pattern can be optionally enclosed using one of the following

As for the format, this should work correctly: :Cfilter /^from/

4
  • Thanks for the answer, sorry I confused myself. I wish to Keep entries that start with from (I corrected it now). With regards to :Cfilter /^from/ shoudl work, that is interesting. Commented Jun 30, 2022 at 11:04
  • No problem! And yes, I think that should work :)
    – r_31415
    Commented Jun 30, 2022 at 16:59
  • Strange that :Cfilter /^from/ does not work fo rme, its matches nothing (all entries remain) Commented Jun 30, 2022 at 17:13
  • Are you sure there is not an extra space or another character that changes your quickfix input? I tried to replicate your quickfix list and it seems to be working. Before i.imgur.com/43qK3eQ.png and after i.imgur.com/oX2Zo7S.png
    – r_31415
    Commented Jun 30, 2022 at 22:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.