Emacs: How to go to line N
When working on Emacs, we often need to move the cursor to certain line. This post explains how to do that in vanilla and Doom Emacs.
In Vi, you just type colon + number, like
:14 to go to line 14.
Things in Emacs are more interesting.
In Vanilla Emacs, you can invoke the
M-x, and then type out the
goto-line and enter a number for the line.
Or, you can use the shortcut:
Doom Emacs keeps similar keybindings. If you type
C-h k M-g g to
goto-line function, you see all the existing key
Key Bindings esc-map g M-g esc-map g g global-map M-g M-g global-map M-g g goto-map M-g goto-map g
Clearly Doom Emacs binds extra keys to be more tolerant of user errors, e.g., pressing the second g key while the meta key is not released yet.
In Mac OS X, I like to bind
goto-line so that I can press
command + l to do the same thing, instead of pressing the
awkward combo of M-g g.
Malcolm Purvis commented that we can use
C-u <number> M-x goto-line to enter
the line number first. That is a nicer workflow if you are comfortable with Emacs