Other Cursor and Text Motion Commands

Here are a few more easy commands with their suggested keybindings.

(defun point-to-top ()
  "Put point on top line of window."
  (interactive)
  (move-to-window-line 0))
(global-set-key "\M-," 'point-to-top)

"Point" refers to the position of the cursor. This command makes the cursor jump to the top left of the window it's in. The suggested keybinding replaces tags-loop-continue, which I like to put on C-x,:

(global-set-key "\C-x," 'tags-loop-continue)

The next function makes the cursor jump to the bottom left of the window it's in.

(defun point-to-bottom ()
  "Put point at beginning of last visible line."
  (interactive)
  (move-to-window-line -1))
(global-set-key "\M-." 'point-to-bottom)

The suggested keybinding in this case replaces find-tag. I put that on C-x. which in turn replaces set-fill-prefix, which I don't mind losing.

(defun line-to-top ()
  "Move current line to top of window."
  (interactive)
  (recenter 0))
(global-set-key "\M-!" 'line-to-top)

This command scrolls the window so that whichever line the cursor is on becomes the top line in the window. The keybinding replaces shell-command.

There is one drawback to changing the bindings for keys in Emacs. If you become accustomed to a highly customized Emacs and then try to use an uncustomized Emacs (e.g., on a different computer or using a friend's login account), you'll keep pressing the wrong keys. This happens to me all the time. I've essentially trained myself to be unable to use an uncustomized Emacs ...

Get Writing GNU Emacs Extensions now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.