C-x C-b is normally bound to the list-buffers command. The resulting buffer has various columns, which are CRM, Buffer, Size, Mode, and File.

When I can click on the Buffer column-header, it will toggle sorting the contents of the window, switching between ascending and descending sorting according to the buffer name. Which is fine. However, the sorting according to the buffer name is case-sensitive.

What I would prefer is for the contents of the window to sort with the buffer name being considered case-insensitively. As it is now, for ascending order, names that begin with (A-Z) are shown first, then names (a-z) are shown after them. I would prefer if the case of the letters was ignored, when sorting by buffer name.

1 Answer 1


list-buffers uses tabulated list sorting, which I've not delved into. ibuffer OTOH has a specific command for sorting by name, and you could redefine it to be case-insensitive like so:

(with-eval-after-load 'ibuf-ext
  ;; Create a case-insensitive ibuffer sort command.  Derived from
  ;; `ibuffer-do-sort-by-alphabetic' which is defined in ibuf-ext.el
  ;; by (define-ibuffer-sorter alphabetic ...).
  (define-ibuffer-sorter alphabetic-ignore-case
    "Sort the buffers by their names, ignoring case."
    (:description "buffer name")
     (buffer-name (car a))
     (buffer-name (car b))
     nil t))
  ;; Assign the new command to the 'Name' header keymap.
  (define-key ibuffer-name-header-map [(mouse-1)]
  (put 'ibuffer-make-column-name 'header-mouse-map

ibuffer is a super-charged replacement for list-buffers so I recommend binding C-x C-b to this (and then doing some reading about its excellent features -- use ? in the buffer or C-h f ibuffer-mode to read its primary help).

  • I delved a little bit into tabulated-list and could not find an easy way to implement what the OP requested. The best that I could do was to redefine tabulated-list--get-sorter to use string-collate-lessp instead of string< (which is hard-wired, hence the need to rewrite the function)t. +1 for ibuffer.
    – NickD
    Feb 12, 2021 at 3:32
  • Thank you phils for a rapid response, and that solution! Two things though ... 1. I put it into my .emacs file and evaluated the .emacs buffer so that it is in effect. But then when going into list-buffer and testing it, it didn't work. I am running latest emacs on Windows 10. [GNU Emacs 27.1 (build 1, x86_64-w64-mingw32) of 2020-11-19] 2. I have seen the ibuffer before, and it has the same issue, except the column is called "Name" in ibuffer. The good news is that your solution DOES work in the ibuffer for the "Name" column!
    – Rolly
    Feb 12, 2021 at 4:23
  • @phils -- My comment above ... I should have read your suggested answer a little more closely. Your solution IS for the ibuffer. And I have confirmed it works, as mentioned in my comment above. Thanks! +1 @NickD -- If I insist on using list-buffers rather than ibuffer (probably I will switch to using ibuffer always, as suggested), then I can try your fix to the hard-wired function, as you indicated, for the list-buffers. So thanks all around!
    – Rolly
    Feb 12, 2021 at 4:41
  • Yes, this answer doesn't affect list-buffers at all. If you like ibuffer though you can (global-set-key (kbd "C-x C-b") 'ibuffer) and then just forget about the default list-buffers.
    – phils
    Feb 12, 2021 at 4:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.