Skip to content

Auto completion

Auto completion is disabled by default for safety and unobtrusiveness. Note that completion can be vulnerable to arbitrary code execution. Auto completion can be enabled by setting corfu-auto to t. Only enable auto completion locally in trusted buffers or globally if you edit trusted files only.

You may want to configure Corfu to quit completion eagerly, such that the completion popup stays out of your way when it appeared unexpectedly.

emacs-lisp
;; Enable auto completion, configure delay, trigger and quitting
(setq corfu-auto t
      corfu-auto-delay 0.2
      corfu-auto-trigger "." ;; Custom trigger characters
      corfu-quit-no-match 'separator) ;; or t

I suggest to experiment with the various settings and key bindings to find a configuration which works for you. There is no one perfect configuration which fits all. Some people like auto completion, some like manual completion, some want to cycle with TAB and some with the arrow keys.

In case you like auto completion settings, where the completion popup appears immediately, better use a cheap completion style like ‘basic’, which performs prefix filtering. See the next section about setting Corfu-only completion styles. In this case Corfu completion should still be fast in buffers with efficient completion backends. You can try the following settings in an Elisp buffer or the Emacs scratch buffer. Note that such settings can slow down Emacs due to the high load on the Lisp runtime and garbage collector.

emacs-lisp
(setq corfu-auto        t
      corfu-auto-delay  0  ;; TOO SMALL - NOT RECOMMENDED!
      corfu-auto-prefix 0) ;; TOO SMALL - NOT RECOMMENDED!

(add-hook 'corfu-mode-hook
          (lambda ()
            ;; Settings only for Corfu
            (setq-local completion-styles '(basic)
                        completion-category-overrides nil
                        completion-category-defaults nil)))