0

Trying to mirror my neovim setup in emacs I haven't found a way to make C-v and M-v scroll smoothly, i.e., line by line. Most solutions I looked at improve mouse and point scrolling, but not the before-mentioned shortcuts. Do I miss something?

2
  • There is scroll-up/down-line: they are not bound to keys, but you can do that yourself. Not sure whether they are what you are looking for however.
    – NickD
    Commented Mar 1, 2023 at 19:53
  • @NickD I want to replicate this motion. Commented Mar 1, 2023 at 19:55

1 Answer 1

2

a way to make C-v and M-v scroll smoothly, i.e. one line at a time.

Maybe you can see 5.44 How can I force Emacs to scroll only one line when I move past the bottom of the screen?:

Customize the scroll-conservatively variable with M-x customize-variable RET scroll-conservatively RET and set it to a large value like, say, 10000. For an explanation of what this means, see Auto Scrolling in The GNU Emacs Manual.

Alternatively, use the following Lisp form in your .emacs:

(setq scroll-conservatively most-positive-fixnum)

It will change the behaviors of C-p and C-n. If you consist on changing the behaviors of C-v and M-v, bind the corresponding function (the function bound to C-p and the function bound to C-n) to M-v or C-v. (Not recommended, because C-v and M-v are there for you to move faster.)


Update:

Maybe you want this:

;; C-v
(progn
  ;; unbind `scroll-up-command` from `C-v`
  (global-unset-key [?\C-v])
  ;; bind the function you want to `C-v`
  (global-set-key [?\C-v]
    #'(lambda ()
        (interactive)
        (let ((number-of-lines 15) ; scroll N lines
              (seconds/line 0.05)) ; spend N seconds scrolling one line
          ;; execute what you want:
          ;; “one line at a time”  
          (dotimes (_ number-of-lines)
            ;; Scroll up 1 line,
            ;; but the cursor moves on the screen too.
            (scroll-up-line)
            ;; Move the cursor down 1 line so that
            ;; the cursor doesn't appear to have changed position.
            (next-line)
            (redisplay)
            (sleep-for seconds/line))))))
;; M-v is similar
(progn
  (global-unset-key [?\M-v])
  (global-set-key [?\M-v]
    #'(lambda ()
        (interactive)
        (let ((number-of-lines 15)
              (seconds/line 0.05))
          (dotimes (_ number-of-lines)
            (scroll-down-line)
            (previous-line)
            (redisplay)
            (sleep-for seconds/line))))))
3
  • Seems like my wording has confused you. Scrolling with point near border can be made smoother, but I want C-v to have an animation instead of a sudden jump. Again, this kind of motion is what I'm aiming for. Commented Mar 2, 2023 at 11:26
  • @Trashbin2019np: The answer is updated; hope it helps you :-) I'll explain the details of the code at my leisure, but you can test it for yourself and see if it meets your needs.
    – shynur
    Commented Mar 2, 2023 at 13:13
  • that's really nice! Thank you. Commented Mar 2, 2023 at 13:51

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.