Here is the video version, if you prefer it:
I have learned the basics of Emacs by reading the Emacs tutorial found in Emacs itself – when you open Emacs, the tutorial is in the window below the window where file contents are displayed. Also, before that, one of my friends taught me how to use Emacs, but I needed a refresher.
To install Emacs (which you will most likely have to), type in:
mislav@mislavovo-racunalo:~$ apt-get install emacs
I urge you to go through the Emacs tutorial. It will cover all of the things you need to know. Here I will list the keyboard shortcuts to focus on – you don’t need to remember everything about Emacs, just these things, in my opinion.
Note: C
means CTRL
and M
means ALT
. M-<character>
means press M
and <character>
simultaneously, while C-<character>
means press C
and <character>
simultaneously. <Return>
means Enter on your keyboard.
- To go to the beginning of a file, press
M-<
- To go to the end of a file, press
M->
- Stop commands with
C-g
- Leave just one window open with
C-x 1
- To cut (or, as Emacs calls it, “kill”) from the cursor position to the end of the line, use
C-k
- A uniform method to kill a portion of files contents is as follows: Press
C-<SPC>
(the Space keyboard key), then move your cursor to the end of the text you want to cut (“kill”) and then pressC-w
to cut (“kill”) it - The command for “yanking” (pasting the portion of the text you have cut (“yanked”)) is
C-y
- To access previously “killed” text, use
M-y
– this is useful if you cut two or more pieces of text, and want to access not the most recently cut one – pay attention to this in the Emacs tutorial - To save a file, press
C-x C-s
(in succession) - To find a file to open up in Emacs press
C-x C-f
and press Return - Kill the Emacs session with
C-x C-c
- Undo with
C-x u
- Replace a string by using
M-x
, typingreplace-string
and giving it two arguments – first argument is the string to be replaced and the second argument is the string to replace it with (end each argument with<Return>
); you can press<Tab>
(Tab on your keyboard) when typing inreplace-string
for auto-completion (so that you don’t have to type all of the characters ofreplace-string
) - To search from the current cursor position onward, press
C-s
and type in the search term. As you type the search term in, Emacs will display the results, refining them with each character you type in. PressC-s
again to move forward one search result. Press<DEL>
(Backspace on your keyboard) to move back one search result. If you need to edit your original query, place yourself on the first search match, press<DEL>
and then you will notice your search term losing characters. Terminate the search with<Return>
. - To start the search from the current cursor position backwards, all of the above applies, but you start it with
C-r
, notC-s
.
Those would, in my opinion, be the very basics to focus on while reading the tutorial. Go through the tutorial – shouldn’t take you more than a couple of hours (or, as scientists and programmers like to say – an afternoon).
Hope you learned something useful!
Subscribe to my newsletter to keep abreast of the interesting things I'm doing. I will send you the newsletter only when there is something interesting. This means 0% spam, 100% interesting content.