Skip to content

Filtering Major Modes in Emacs Buffers

Posted on:February 10, 2020

Having adopted emacs-libvterm as my main term, I wanted a first-class way to open and switch between vterm buffers.

With ivy-rich, one can view the major mode of the buffer list when running ivy-switch-bufffer. However, there doesn’t seem to be a way to filter by mode, or anything else, really, aside from buffer name.

I’m not quite happy with this yet, but I wrote this:

(defun sy/search-vterm()
  (interactive)
  (counsel-ibuffer)
  (ibuffer-filter-disable)
  (ibuffer-filter-by-mode 'vterm-mode))
 
(map! "C-c C-v" #'sy/search-vterm)

which first runs swiper on ibuffer, clears the existing ibuffer filters, then filters by 'vterm-mode. Of course, this can be swapped out for any other mode you like.

sy/search-vterm

Swiper in action