Scrolling Emacs by Line

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+v1.

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.

This entry was posted in General and tagged . Bookmark the permalink.
  • chrm

    I suggest centered cursor mode, it makes the cursor stay vertically centered in the middle of the frame. This way you can always see whats near the cursor. And if you can't see far enough this way, while editing a line, it's time to refactor the function ;-)

  • PabloM

    I use Ctrl + l (that's an L) to center the buffer in the current line once I found what I was looking for and I want to see the context.

  • add this to you .emacs file and it will make the scrolling like in vim:

    (setq scroll-step 1
    scroll-conservatively 10000)

    Hope that helps :-)