Orderless completion
Orderless is an advanced completion style that supports multi-component search filters separated by a configurable character (space, by default). Normally, entering characters like space which lie outside the completion region boundaries (words, typically) causes Corfu to quit. This behavior is helpful with auto-completion, which may pop-up when not desired, e.g. on entering a new variable name. Just keep typing and Corfu will get out of the way.
But orderless search terms can contain arbitrary characters; they are also interpreted as regular expressions. To use orderless, set corfu-separator (a space, by default) to the primary character of your orderless component separator.
Then, when a new orderless component is desired, use ‘M-SPC’ (corfu-insert-separator) to enter the first component separator in the input, and arbitrary orderless search terms and new separators can be entered thereafter.
To treat the entire input as Orderless input, you can set the customization option corfu-quit-at-boundary to nil. This disables the predicate which checks if the current completion boundary has been left. In contrast, if you always want to quit at the boundary, set corfu-quit-at-boundary to t. By default corfu-quit-at-boundary is set to separator which quits at completion boundaries as long as no separator has been inserted with corfu-insert-separator.
Finally, there exists the user option corfu-quit-no-match which is set to ‘separator’ by default. With this setting Corfu stays alive as soon as you start advanced filtering with a corfu-separator even if there are no matches, for example due to a typo. As long as no separator character has been inserted with corfu-insert-separator, Corfu will still quit if there are no matches. This ensures that the Corfu popup goes away quickly if completion is not possible.
In the following we show two configurations, one which works best with auto completion and one which may work better with manual completion if you prefer to always use ‘SPC’ to separate the Orderless components.
;; Auto completion example
(use-package corfu
:custom
(corfu-auto t) ;; Enable auto completion
;; (corfu-separator ?_) ;; Set to orderless separator, if not using space
:bind
;; Another key binding can be used, such as S-SPC.
;; (:map corfu-map ("M-SPC" . corfu-insert-separator))
:init
(global-corfu-mode))
;; Manual completion example
(use-package corfu
:custom
;; (corfu-separator ?_) ;; Set to orderless separator, if not using space
:bind
;; Configure SPC for separator insertion
(:map corfu-map ("SPC" . corfu-insert-separator))
:init
(global-corfu-mode))