reddit / emacs

How to keep the cursor centered when at bottom of a buffer?

randdis · 2022-03-22 11:13
Hi all, I would like to keep my cursor always in the middle of the screen, even if I'm writing at the bottom of a buffer. I added the following snippet to my init.el (use-package centered-cursor-mode :ensure t :init (global-centered-cursor-mode 1) ) (setq scroll-margin 28) ;; full screen = 57 lines (setq-default indicate-empty-lines t) but it doesn't work and the cursor is only around 25% of the buffer. see here : https://imgur.com/3glkqEa.png (also I assume I should set a hook because I don't want to loose 50% of screen space for terminal type buffers) Thanks,
DeepDay6 · 2022-03-22 13:31
`C-l`?
randdis · 2022-03-22 14:35
`centered-cursor-mode` does that automatically. And as `centered-cursor-mode` , `C-l` doesn't center at the bottom of a buffer.
arthurno1 · 2022-03-23 07:39
> C-l? It is bound to recenter-top-bottom, which as the names says, moves the buffer and the cursor to top, bottom and center (in that order). But one can : (define-key global-map (kbd "C-l") #'recenter) to make the cursor to only recenter the buffer. However, it is not the same as always keeping the cursor in the center. For that, I think one has to do some scrolling of the buffer instead of moving the cursor, if it is even possible to *always* keep the cursor in the center.
csname · 2022-03-26 09:30
Have you looked into setting `ccm-recenter-at-end-of-file` to `t`?
randdis · 2022-04-26 15:33
Yes, that's it ! thanks a lot !