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.
M-<character> means press
<character> simultaneously, while
C-<character> means press
<Return> means Enter on your keyboard.
- To go to the beginning of a file, press
- To go to the end of a file, press
- Stop commands with
- Leave just one window open with
- To cut (or, as Emacs calls it, “kill”) from the cursor position to the end of the line, use
- 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 press
C-wto cut (“kill”) it
- The command for “yanking” (pasting the portion of the text you have cut (“yanked”)) is
- 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-fand press Return
- Kill the Emacs session with
- Undo with
- Replace a string by using
replace-stringand 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 in
replace-stringfor auto-completion (so that you don’t have to type all of the characters of
- To search from the current cursor position onward, press
C-sand 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. Press
C-sagain 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
- To start the search from the current cursor position backwards, all of the above applies, but you start it with
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!