Emacs Tip: Scroll Current Line to the Top of the Window

Emacs is my editor of choice when I'm not in Eclipse. For the most part, I actually think I'm more efficient in Emacs due to there being a key-binding for everything. (Yes...I know there are emacs bindings for Eclipse but I've not had the time to try them yet.) One thing I've never found was a way to make the current line that my cursor is on the top of the window. I started looking through the scrolling section of the Emacs Manual and I found some information about using C-l for scrolling, instead of just clearing the screen. After messing around, I found a simple command that will put the line that the cursor is currently on at the top of the window:

  1. C-u 0 C-l

Presto...no matter what type of file you have open, you can immediately make the Emacs window scroll to make the current line the top of the window.

(Note: I do not claim to be an Emacs expert. I just thought this was useful and since Google was turning up so many false positives, I wanted to preserve this for posterity.)

Comments

Useful tip, and you succeeded where Google is concerned. For me the search "emacs put current line at top of window" brought this page up as the top hit.

Great tip also, Thank you. Worth noting that C-u 2 C-l will scroll so the current line is 2 lines from the top. etc.