Vertico

about | blog | config | notes | github

1. Vertical Interactive Completion

vertico is a minimal completion UI for GNU/Emacs. It is built ontop of the regular completion system unlike other alternatives.

2. Configuration

2.1. Enable Dependencies

In order to make vertico completion a lot nicer that what it is, we make use of the Orderless package which enables orderless completion modes in various completion buffers.

(require 'init-orderless)

We also wan to have multiple minibuffers open, we can set this up with the Recursion Indicator package so we know how many minibuffers are on the stack.

(require 'init-recursion-indicator)

2.2. Package Install

Setup the vertico package.

(use-package vertico
  :bind (:map vertico-map
         ("?"   . minibuffer-completion-help)
         ("M-j" . vertico-next)
         ("M-k" . vertico-previous)
         ("M-f" . vertico-exit)
         :map minibuffer-local-map
         ;; See section below of directory movement
         ("S-<backspace>" . zamlz/minibuffer-backward-kill))
  :init
  (vertico-mode))

Allow vertico to cycle between results

(setq vertico-cycle t)

Let's also set the max size of vertico minibuffers.

(setq vertico-count 16)

But let's also make sure vertico is able to resize itself

(setq vertico-resize t)

2.3. Persist History

Persist history over Emacs restarts. Vertico will sort by history position for all completion buffers.

(savehist-mode +1)

2.4. Better Minibuffer Support

Resize the minibuffer on the fly as completion shrinks.

(setq resize-mini-windows t)

Do not allow the cursor in minibuffer prompts

(setq minibuffer-prompt-properties
      '(read-only t cursor-intangible t face minibuffer-prompt))
(add-hook 'minibuffer-setup-hook #'cursor-intangible-mode)

I actually I'm kinda unsure about the purpose of this block. I saw it in the original example for vertico's github page and copied it.

(defun crm-indicator (args)
  (cons (concat "[CRM] " (car args)) (cdr args)))
(advice-add #'completing-read-multiple :filter-args #'crm-indicator)

2.5. Upwards Directory Movement in find-file

I stole this little snippet of code from David (System Crafters). It basically mimics the same behaviour that counsel-find-file has when using <Backspace>, that is, it would essentially delete the characters in the path string such that it would go up a directory. This does the same thing now, but in vertico.

(defun zamlz/minibuffer-backward-kill (arg)
  "When minibuffer is completing a file name delete up to parent
folder, otherwise delete a character backward"
  (interactive "p")
  (if minibuffer-completing-file-name
      ;; Borrowed from https://github.com/raxod502/selectrum/issues/498#issuecomment-803283608
      (if (string-match-p "/." (minibuffer-contents))
          (zap-up-to-char (- arg) ?/)
        (delete-minibuffer-contents))
      (delete-backward-char arg)))

2.6. Feature Provide

(provide 'init-vertico)

Created: 2021-11-13

Emacs 26.1 (Org mode 9.5)