How do I clear all entries from the quickfix list in Vim?
Answer
:cexpr []
Explanation
After a :grep, :make, or :vimgrep run, the quickfix list fills with results. Sometimes you want to start fresh without opening a new session or running a search that intentionally returns nothing. :cexpr [] achieves this instantly by evaluating an empty Vimscript list as the new quickfix list content, replacing all existing entries with zero entries.
How it works
:cexpr {expr}— sets the quickfix list by evaluating{expr}and interpreting the result as error-format output; when given an empty list[], it produces an empty quickfix list- This is more direct than running a search that matches nothing, and cleaner than closing and reopening the window
Example
" After a :grep that filled the quickfix list with many results:
:copen " see the cluttered list
:cexpr [] " clear it
:copen " now shows: (Empty quickfix list)
Tips
- Use
:lexpr []to clear the location list of the current window instead of the global quickfix list - After clearing,
:ccloseto close the now-empty window - Alternatively,
:cclose | cexpr []in one command sequence - The quickfix history (navigable with
:colder/:cnewer) is preserved — only the current list is cleared - Useful in mappings or scripts that conditionally populate the quickfix list