The other day, I stumbled across this post over at Anything goes about scrolling up and down by line in Emacs. The poster gives two simple functions and some key bindings to scroll a window up or down a line. In the comments, Jürgen notes that 【Ctrl+v】 and 【Meta+v】 are already bound to scrolling the window and that you can scroll by line instead of page by giving a prefix argument. Thus, to scroll down one line you would type 【Ctrl+u 1 Ctrl+v】 or even easier 【Ctrl+1+v】1.
This is often convenient when you’re editing and want to see a few lines above the top of the window or below the bottom of the window. I used to do that by using 【Meta+r】 to move the point to the top/center/bottom of the window and then move the point up or down to scroll a line or two. That worked OK, I suppose, until I started using
paredit, which rebinds 【Meta+r】 to
paredit-raise-sexp. That made using 【Meta+r】 to scroll useless when editing Lisp or Scheme files so I would generally scroll up or down a page to see those hidden lines.
Adding a prefix to 【Ctrl+v】 and 【Meta+v】 to scroll by line is one of those things I’m sure I learned in the past but had forgotten. I’m glad to be reminded because it’s surprising how often the need to do so comes up.
1 If you’re on a Mac and are using
Spaces, you may have to change the
Spaces preferences to use 【⌘ Cmd+num】 instead of 【Ctrl+num】 to switch to a specific space. That’s because OS X will intercept the 【Ctrl+num】 and Emacs won’t see it.