next up previous
Next: Emacs documentation Up: Introduction to emacs Previous: Notation

Basic Emacs commands

At this point you should have your Emacs installed and your terminal shortcut ready somewhere on your desktop. Open the terminal by double-clicking on its icon, type emacs and execute the command by pressing Enter. You should now see the Emacs window with an empty buffer which is that part of the window which occupies the largest area. The bottom part of the window should look similarly like:

  --:--  *scratch*      (Lisp Interaction)--L1--All-------------------------------
It means that you are now in the scratch mode in which you can practice typing, copying, deleting, searching and replacing your text. I strongly recommend you to spend some time playing with this editor prior to reading the following section. Although Emacs is an excellent programmer's editor which can help you tremendously to keep your source code clear, it requires a knowledge of certain simple operations with your text. Emacs is not like any other simple text editor and also its keyboard shortcuts differ from other editors. Do not be scared when you find that Home jumps to the beginning of buffer, instead of to the beginning of line. This feature can be simply changed to emulate the behavior of other editors, but this is rather advanced operation which we leave for your future exploration of Emacs.

Following is the list of the most useful commands which you will often need. Try testing each of them in the scratch window of Emacs to make sure that you know how they are actually executed.

Enter - new line
Tab - tabulator (the tab width is dependent on the Emacs mode)
C-x C-f - opens a file and shows it in the current buffer
C-x C-s - saves the buffer
C-x C-w - writes the buffer in a different file (Save As)
C-x C-c - quits emacs C-a - jump to the beginning of the current line
C-e - jump to the end of the current line
M-f - move forward one word
M-b - move backward one word
M-< - move to the top of the buffer
M-> - move to the bottom of the buffer
M-x goto-char - read a number $n$ and move to the line number $n$. C-d - delete the character at the cursor
C-k - kill (delete) the text from the position of cursor to the end of the current line
M-d - kill (delete) forward until the end of the next word
M-Del - kill (delete) backward until the beginning of a previous word C-s - search forward (searching towards the end of the current buffer)
C-r - search backward (searching towards the top of the current buffer)
M-% - replace forward C-SPC - mark beginning of the text for copying/moving/deleting
C-w - cut the text from buffer to the clipboard
C-y - yank (paste) the text from the clipboard at the position of the cursor C-_ - undo the last change
ESC ESC ESC - cancel the last operation (try it after C-x C-w)

Once you finish writing your scratch text, you can try saving it by executing C-x C-s. The minibuffer at the bottom of your screen now asks for the file name, File to save in:. To replace an existing file, you can always press Tab during writing the file name and Emacs automatically adds the rest of the name, provided that it can be uniquely identified. Pressing Tab once more opens a new buffer which shows you the directory structure and allows you to find the target directory manually by clicking on folders.

next up previous
Next: Emacs documentation Up: Introduction to emacs Previous: Notation
Roman Groger