I'm trying to achieve both:

  • persistent centered cursor (cursor stays in center of a window except when near the line 0 and count-lines-page
  • augment the way evil-window-bottom and evil-window-top work so that calling those functions scrolls to the corresponding position, then subsequently "re-centers" the cursor. This would be similar to a full page down, divided by 2

How can I do this?

I'm on Emacs version 26.3, and evil-mode version evil-git-af6ca28, although I don't think these matter much.

I found a centered cursor implementation which works well enough for me (with the exception that it entirely breaks evil-window-bottom and evil-window-top):

(setq scroll-preserve-screen-position t
      scroll-conservatively 0
      maximum-scroll-margin 0.5
      scroll-margin 99999)

evil-window-bottom (keybind L) and evil-window-top (keybind H) no longer work because they depend on scroll-margin. I'd like to create new functions (and bind them to the same keys, L and H) such that (move-to-window-line -1) (for window bottom) or (move-to-window-line 0) (for window top) moves to the cursor position (centered in the window).

I've tried modifying scroll-margin, but I don't think this can be done interactively, and doubt this is the best approach anyway. Next I'm literally looking at just overriding / replacing the definitions for the evil-window-bottom and evil-window-top functions. How should I do that? I could almost just override the functions, hardcoding scroll-margin with 0, but this wouldn't handle the cursor position (I think). What is the recommended approach?


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.