Emacs equivalent of vim’s shift-h and shift-l

cursor-positionemacsnavigationvim

i'm wondering if emacs has these cursor movement commands built in or if i'm going to have to write them or find a snippet somewhere. i find them pretty spiffy and use them in vim regularly. i haven't found them in emacs' documentation so far.

in vim, they look like this:
shift-h -> move cursor to the top of the screen
shift-m -> move cursor to the middle of the screen
shift-l -> move cursor to the bottom of the screen

just to clarify, i'm not looking to move the cursor to the top/bottom of the document, just to the top/bottom of the currently visible part of the document, i.e. the part that's currently being displayed on screen.

i found one of them so far. alt-r seems to be the equivalent of vim's shift-m. it moves the cursor to the first column of the middle line.

Best Answer

Use:

  • Alt+0 Alt+r - top of Window
  • Alt+- Alt+r - bottom of Window

Strictly, these should be written as M-0 M-r for the top of the screen and M-- M-r for the bottom of the screen. Where M means the Meta key which is usually mapped to Alt.

I worked out these keystrokes as follows:

M-r runs the command move-to-window-line. I found this out with C-h k M-r, ie. Ctrl+h, k, Alt+r. The key sequence C-h k means tell me what the next key sequence does. It told me the command name and also that you can pass numeric arguments to the command to pick the line you want to go to. If you don't pass any it moves the point to the middle of the window as you have seen.

You pass numeric arguments to commands by typing a number while holding down Meta. A minus sign on its own is taken to mean -1. Now, to move to the top of the screen we want to pass line 0 and for the bottom of the screen line -1. This gives us the key sequences above.

If you want to bind move-to-window-line to a different key look at Joe's answer to this question.