Scrolling It's an integral part of just about any graphical user interface, including emacs. However, I always found that the default way scrolling works in emacs left something to be desired. It puts the scroll bar on the left (!), and when scrolling around, it does not scroll smoothly, but instead it seem to do so in bursts. But, this being emacs, we can change it!

First, the position of the scroll bar. Presumably for historical reasons, emacs puts the scroll bar on the left of the window, unlike most other programs. We can easily change that, by putting the following in .emacs (or ~/.emacs.d/init.el):

(set-scroll-bar-mode 'right)

Instead of right, you can also use left, or nil to hide the scroll bar completely. You can also do this through the menu (Options / Show/Hide / Scroll bar). Note that on X, when the cursor (point) reaches the end of the document, the slider on the scroll bar may not be at the bottom; I understand this is because of some disagreement between Emacs and the toolkit (GTK+ in this case).

Now, what about the other issue, the non-smoothness when scrolling with the cursor-keys or with C-n, C-p? Below are my settings for making scrolling a bit smoother, and the explanation. Of course, these are just my personal preferences.

  scroll-margin 0                  
  scroll-conservatively 100000
  scroll-preserve-screen-position 1)
  • The scroll-margin. This determines when scrolling should start; by setting it to 0, emacs will start to scroll whenever you are entering the top or bottom line of the window. You can also this to, say, 5 to let scrolling start whenever you're getting closer than 5 lines from top or bottom
  • Then, scroll-conservatively determines how far the cursor is allowed to be distanced from the center of the screen when scrolling start. The default sets this to 0, which means that whenever you start scrolling, the cursor jumps to the center of the screen. I find that quite annoying, so I set it to some big number (the 'effective maximum' for that is lines-in-window / 2, but you can put any bigger number there to avoid the jumpiness)
  • scroll-preserve-screen-position tries to maintain the current screen position when you scroll using Page-Up/Page-Down. I like that.

There are also the variables scroll-up-aggressively and scroll-down-aggressively. Normally, they determine how far emacs will scroll (up and down, respectively) when it does so. However, they don't make any difference with a big scroll-conservatively like I am using. Still, if you want to play with it, their values are fractions between 0.0 and 1.0 (inclusive); a value of 1 means that it will move a full screen when scrolling starts, a value of 0.0 causes a move of only one single line.


Anonymous said...

Having the scrollbar on the left makes more sense to me when working with text in a left-to-right language. It's easier to keep the scroll thumb in view while scanning down the left side of the text. I assume that's the reason for the default behavior

lifealgorithms said...

Ah, very comfortable.
This unconventional scrolling has always been a bit annoying. With the default setting one easily loses context.

I chose a scroll-margin of 10 now. I think, no scroll-margin might lead to having to scroll backwards when you overshoot your target.

Larry Stewart said...

Scroll bars should be on the left. Because other programs get this wrong doesn't mean emacs should make their mistakes.

The scroll bar should be on the left because it requires shorter mouse movements, on average, to reach the scrollbar than if it were on the right.

The original GUIs, at Xerox PARC, had the scrollbars on the left. Apple and Microsoft changed this, making it worse, when they did their GUIs.

djcb said...

@Anonyous, @Larry Stewart: it's good emacs lets you customize the scroll bar then. I find it somewhat visually distracting to have the scroll bar on the left; and being used to have it on the right in other programs plays a role as well. There is no 'wrong' or 'right' here, just personal preference.

Andy said...

You might also like to check out


ryanm2215 said...

question: how do I make shift+up_arrow scroll up when using eshell? i find that behaviour extremely frustrating as well.

Anonymous said...

There is one issue with Emacs' scrolling that I have never been able to understand. When using the scrollbar, just to have a quick look of a file, it doesn't scroll smoothly at all. This is because the height of the scrollbar knob is relative to characters shown instead to lines.

In normal editors, the scroll knob size depends on how many lines are displayed, which is a number that remains constant for a fixed window (in emacs-parlance) height. Instead, Emacs sets the knob height according to the displayed characters relative to the file size. This means that the knob will appear very small if the visible lines are sparsely populated, while it will be very tall if the shown lines are dense.

The scroll bar is supposed to give feedback about the visible portion of the file and the rest of it.

I do not know of any workaround and I'm not sure if it has a solution. Has anyone else seen or experienced this issue?


j said...

Scroll bars should be on the left. Because other programs get this wrong doesn't mean emacs should make their mistakes.

People should drive on the left. That the United States gets this wrong doesn't mean that drivers there should make the same mistake.

...The point being, of course, that even a sub-optimal convention needs to be followed, else confusion and grief are an obvious and avoidable result.

Anonymous said...

I personally prefer

(scroll-bar-mode nil)


ryanm2215 said...

so, does anyone know how to scroll up in eshell? shft+pgUP works, but now very well, and it selects everything, while I just want to veiw previous output.

djcb said...

@ryanm2215: both PgUp/PgDown and C-n, C-p work well for me.

ryanm2215 said...


Greg said...

Does anyone know whether scroll-preserve-screen-position conflicts with track-eol? If I set the latter to t, it does not seem to do anything.

Vincent D. said...

Hi, does anyone know how to use the mouse to scroll in emacs in the terminal (-nw) ? I'd find it useful sometimes, for example to show my code to other people. The problem is that the mouse-wheel buttons move the point instead of the buffer.
Thx !

Lex Fridman said...

I posted a question about something you brought in this post on StackOverflow. Specifically, the fact that the scrollbar slider doesn't go all the way to the bottom:


Let me know if you've figured out a solution to this.

djcb said...

@Lex Fridman: I don't know of any solution to this. Anyway, I'm not even using the scrollbar anymore, instead I moved to sml-modeline.