Ivy Completion Framework

about | blog | config | notes | github

1. A Generic Completion Framework for Emacs

Ivy is a generic completion mechanism for GNU/Emacs. Currently this is disabled…

2. Configuration

2.1. Counsel

Counsel on the other hand, provides replaces commands that replace the typical emacs commands.

(use-package counsel
  :disabled
  :bind (
         ("M-x"       . counsel-M-x)
         ("C-x TAB"   . counsel-semantic-or-imenu)
         ("C-x b"     . counsel-switch-buffer)
         ("M-y"       . counsel-yank-pop)
         ("M-o"       . counsel-recentf)
         ("M-m"       . counsel-evil-marks)
         ("C-x B"     . counsel-switch-buffer-other-window)
         ("C-x C-f"   . counsel-find-file)
         ("C-x C-M-f" . counsel-find-file-extern)
         ("C-x C-l"   . counsel-locate)
         ("C-x C-M-l" . counsel-locate-action-extern)
         ("C-x C-v"   . counsel-set-variable)
         ("C-c u"     . counsel-unicode-char)
         :map minibuffer-local-map
         ("C-r"       . 'counsel-minibuffer-history))
  :config (counsel-mode)
  )

2.2. Ivy

Ivy is basically a completion framework. Its minimal but provides a simple but powerful menu that appears when switching files, opening buffers, etc.

(use-package ivy
  :after counsel
  :init
  (setq ivy-re-builders-alist `((t . ivy--regex-ignore-order)))
  (ivy-mode)
  :bind (:map ivy-minibuffer-map
         ("TAB" . ivy-alt-done)
         ("C-l" . ivy-alt-done)
         ("C-j" . ivy-next-line)
         ("C-k" . ivy-previous-line)
         :map ivy-switch-buffer-map
         ("C-k" . ivy-previous-line)
         ("C-l" . ivy-done)
         ("C-d" . ivy-switch-buffer-kill)
         :map ivy-reverse-i-search-map
         ("C-k" . ivy-previous-line)
         ("C-d" . ivy-reverse-i-search-kill))
  :custom
  (ivy-height 14)
  (ivy-wrap t)
  (ivy-fixed-height-minibuffer t)
  (ivy-count-format "[%d/%d] ")
  ;; Don't start searches with ^
  (ivy-initial-inputs-alist nil)
  ;; Show recentf files in buffer switch
  (ivy-use-virtual-buffers nil)
  ;; Show the full virtual file paths
  (ivy-virtual-abbreviate 'full)
  ;; Do not quit the minibuffer on delete-error
  (ivy-on-del-error-function #'ignore)
  ;; Enable ability to select the prompt
  (ivy-use-selectable-prompt t))

2.3. Ivy Rich

Ivy-Rich provides extra columns in the counsel commands to get more information about each item during autocompletion.

(use-package ivy-rich
  :after ivy
  :custom
  (ivy-virtual-abbreviate 'full
                          ivy-rich-switch-buffer-align-virtual-buffer t
                          ivy-rich-path-style 'abbrev)
  :config
  (setcdr (assq t ivy-format-functions-alist) #'ivy-format-function-line)
  (ivy-set-display-transformer 'ivy-switch-buffer
                               'ivy-rich-switch-buffer-transformer)
  :init (ivy-rich-mode 1))

Make ivy rich even more aesthetic with icons!

(use-package all-the-icons-ivy-rich
  :after (counsel counsel-projectile)
  :init (all-the-icons-ivy-rich-mode 1))

2.4. Swiper

(use-package swiper
  :after counsel
  :custom (swiper-action-recent t)
  :bind (("C-s"   . swiper)
         ("C-M-s" . swiper-all)))

2.5. Ivy Hydra

Ivy Hydra is part of the original repo, but its bundled seperately as a package. These lets us drop into a hydra session while we are in a ivy minibuffer.

(use-package ivy-hydra
  :after (ivy hydra))

2.6. Ivy Bibtex

(use-package ivy-bibtex
  :after ivy
  :bind (("C-c n p"   . ivy-bibtex)
         ("C-c n C-p" . ivy-bibtex-with-notes))
  :custom
  (bibtex-completion-bibliography `((,(directory-files-recursively "~/org/papers/bib/" ""))))
  (bibtex-completion-library-path '("~/org/papers/doc/"))
  (bibtex-completion-notes-path "~/org/papers/notes/")
  ;; Style the output indicators
  (bibtex-completion-pdf-symbol "⌘")
  (bibtex-completion-notes-symbol "✎")
  ;; TODO Use bibtex-completion-additional-search-fields
  (bibtex-completion-notes-template-multiple-files
   (concat "#+TITLE: Notes on \"${title}\" by ${author-or-editor} (${year})\n"
           "#+AUTHOR: %n (%(user-login-name))\n"
           "#+ROAM_ALIAS:\n"
           "#+ROAM_TAGS:\n"
           "#+ROAM_KEY: cite:${=key=}\n"
           "#+CREATED: %U\n"
           "#+LAST_MODIFIED: %U\n"))
  )

2.7. Counsel Projectile

Provides counsel interface for projectile.

(use-package counsel-projectile
  :after counsel
  :init (counsel-projectile-mode))

2.8. Package Provides

(provide 'init-ivy)

Created: 2021-11-13

Emacs 26.1 (Org mode 9.5)