C-x b RET for automatically switching to last buffer

I use emacs, and my muscle memory is to use C-x b RET for accessing the last buffer. This works because the buffer list places the last buffer at the top of the list. But right now in nyxt, the current buffer is at the top of the list, making C-x b RET not do anything.

Is there a way to simulate an equivalent funtionality? I would like some pointers, then I can probably write something up myself.

EDIT: I noticed a mention of switch-buffer-last, but I don’t see it when I C-h f. Where can I find it?

I use vi-bindings and for me switch-buffer-last is bound to C-backquote. See source/buffer.lisp and source/base-mode.lisp for the source of this command. You could map it to another binding but I am not sure how to make it work with C-x b Return as you would want without changing the way buffers are sorted.

More than just switch-buffer-last, I think a good alternative would be to have bindings to switch buffers sorted by recency. They could be ranked depending on how many switch-buffer actions back they were last shown, and switch-buffer-recency-forward and switch-buffer-recency-backward would switch buffers in that order. Of course the switch-buffer-recency-* commands should not alter the ranking, else it would be a mess because the rank would change every time we use the commands.

I remember discussing that on IRC with @jmercouris who told me C-[ and C-] do exactly that, but I failed to reproduce the expected behavior with that lately, so maybe this has changed (those bindings just switch buffers in the same order as [ and ] for me). My expectations would be that [ and ] cycle through buffers in the order they were first created, and C-[ and C-] in the order they were last shown with a command different from C-[ and C-] themselves.

I noticed a mention of switch-buffer-last, but I don’t see it when I C-h f. Where can I find it?

I guess you need to update your nyxt: switch-buffer-last is comparatively recent.

I ended up finding :current-is-last-p on the latest version, which does exactly what I want.


(define-command switch-buffer* ()
	(switch-buffer :current-is-last-p t))

It’s in the most recent manual, as well (which is very helpful).

1 Like