Watch the video on YouTube!
We covered the basics of using Emacs in The Absolute Beginners' Guide to Emacs but we didn't really get a chance to talk about the key bindings you might want to use to navigate around file buffers.
In this video I'll show you the built-in bindings you can use to move around in a file very efficiently without moving your fingers from the letter keys!
I will also tell you the exact Emacs commands that these keys bind to so that you can bind them to new keys if you like or even use them directly in Emacs Lisp code!
I recommend opening a text buffer in Emacs while watching this episode so that you can try these bindings and follow along.
In Emacs, the term "point" refers to the location of the cursor in a given buffer. The point is the place where text will be inserted when you type and its location can be changed using movement keys.
Emacs allows you to use the arrow keys to move the point just like in many typical text editors.
In addition to the arrow keys, Emacs also provides a set of movement keys using alphabetical letters. The interesting thing is that these keys are chosen because of the words they map to so that they are easy to remember!
Basic point movements are done using the keys I mentioned above in combination with the CTRL key:
The benefit of these bindings is that they are closer to where your fingers already rest on the keyboard. No more moving your right hand to the arrow keys just to navigate around the buffer!
The <LEFT> and <RIGHT> arrow keys are slightly different in that they call left-char and right-char which properly respect the direction right-to-left text!
It's very common to want to move to the beginning or end of a line of text!
You can think of this like:
Sometimes you want to jump to the beginning or end of the buffer quickly!
If you're using the GUI version of Emacs (not in the terminal) you can also press C-<HOME> and C-<END> to accomplish the same thing!
When a compiler tells you an error is on a specific line number, you'll want to know how to get there quickly!
TIP: you can easily show line numbers in a buffer by running M-x display-line-numbers-mode!
There are other bindings that move in larger steps in the buffer, usually corresponding to units that you understand like words, sentences, and paragraphs.
To move forward and backward by words using the same keys, use ALT (Meta):
Note that there is no equivalent for C-n and C-p!
You can move between paragraphs using the following keys:
These keys can also be used in code! The definition of a "paragraph" is basically any section of text that is separated by blank lines (see documentation for the paragraph-start variable).
You can move between sentences using keys similar to jumping to beginning or end of the line:
What qualifies as a sentence is a bit more complex (see documentation for the sentence-end function). If the normal sentence patterns aren't found, it defaults to following paragraph boundaries, so it works in code too!
Aside from using the expected <PageUp> and <PageDown> keys for scrolling the window, you can also use these keys:
The reversed up/down terminology is a little confusing, but it's a more literal description of the direction the buffer contents are moving.
These key bindings can be helpful to move the scroll position to give you context above and below the current line:
You can easily move around in the buffer by searching for text with the following bindings:
These commands are incremental which means that you see the results as you type!
If you keep the prompt open (without pressing <RET>), you can keep pressing the C-s and C-r keys to navigate forward and backward in all the results for this string in the same buffer!
In the next video, we'll talk about how you can select regions of text using Emacs' "mark" commands!
After that, we'll continue covering the fundamental key bindings for editing and manipulating text.