Your first task in mastering Emacs is to just move around. That means opening files, yes. It also means moving around within those files. The navigational features of Emacs (and the various extended functionality available through installable packages) are extensive. We’re going to start with the basics to get you up and running. And I will later suggest ways to augment your experience. You also have the vast ecosystem of Emacs YouTube videos from yours truly and other talented individuals out there. So let’s just start with the basics.
Opening files in dired, the directory editor
“Dired” (pronounced “der,” as in derp, “ed” as in Edward), the “directory editor,” is a powerful file management system in Emacs. Like virtually everything else in Emacs, it’s like a self-contained programming environment within the living environment of the Emacs editor.
With Dired, you can search, view, and open files and directories. For our purposes, that’s just about the extent of what you’ll be using Dired for.
To enter Dired in your current buffer, there’s a simple key command: C-x d
.
To open a file in Dired, there’s another simple key command: C-x C-f
.
Navigating the buffer
Now for the exciting part: moving around the text buffer.
Your default arrow keys on your keyboard will work just fine. You can use the up and down arrows to move up and down a text buffer line by line. This is fine. You can use the left and right arrows to go left and right, one character at a time. This is also fine. But it’s nothing fancy.
Emacs is much more interesting than that. Start using these new commands, and repeat until they’re second nature (and they will be soon enough):
C-n
: next line, or move down one line.C-p
: previous line, or move up one line.C-f
: forward character.C-b
: back character.
That’s just for starters. The keys above will do what your arrow keys do, but you can stay closer to your keyboard’s home row. Already you’re getting faster. But there’s more. Emacs lets you move forward and backward by word too:
M-f
: forward word.M-b
: back word.
I like moving forward by word while editing. But even so, that’s a lot of button-pressing. We can do even better. Emacs lets you move forward by sentence as well.
M-a:
: go to beginning of sentence.M-e
: go to end of sentence.
Pretty cool, huh? This will be enough to get you started with file and buffer navigation. And you will learn more over time.
A special note on keybindings (and a warning)
For new users, the default Emacs keybindings may seem a bit cumbersome. You may be tempted to try out an alternate keymapping, like the popular Evil mode (which ports over Vim keybindings). I would advise avoiding this temptation for now. It is proper and good and right to learn the default Emacs keybindings, even if you are coming over from Vim. Heed my words.
In the next article, you’ll learn more about Org Mode.