Previous in this series : Part 1 – Introduction
Cursor Movement
Unlike Vi, except when executing a command, whenever you type in Emacs, text is inserted or replaced at the current cursor location. Emacs has a variety of commands to move and position the cursor within the buffer. Most of these commands can be executed with single keystroke commands. As seen in the previous article, keystroke commands are executed by holding down the Control (Ctrl) or Meta (Esc) key and pressing another key. The notation for this is C-x or M-x where C- indicates the Control key, M- indicates the Meta key and x indicates any arbitrary key. For ease of reference, I have compiled the most common cursor movement commands below in table format.
| Command |
Action |
| C-b |
Go back one character |
| C-f |
Go forward one character |
| M-b |
Go back one word |
| M-f |
Go forward on word |
| C-p |
Go to the previous line |
| C-n |
Go to the next line |
| C-a |
Go to beginning of line |
| C-e |
Go to end of line |
| M-a |
Go to beginning of sentence |
| M-e |
Go to end of sentenced |
| M-[ |
Go to beginning of paragraph |
| M-] |
Go to end of paragraph |
| M-< |
Go to beginning of buffer |
| M-> |
Go to end of buffer |
| C-v |
Go forward one screen |
| M-v |
Go back on screen |
| C-x [ |
Go back one page |
| C-x ] |
Go forward one page |
| M-m |
Go to first non-blank character |
Most, if not all, current distributions of Emacs bind most of these commands to the keyboard controls keys such as left-arrow, right-arrow, page-up and page-down among other. Most people familiar with similar editing applications should have no difficulty in using certain navigation commands they are already familiar with. Mouse actions are similar to that of most other applications as well, with the exception of certain mouse button click sequences. It is best for the user to experiment with these alternate navigation methods to determine exactly how the behave on their system.
Other cursor movement commands can be executed by verbose commands the most useful of these commands is M-x goto-line, which prompts the user for a line number to move to within the file. If a number larger than the last line in the file is supplied, the cursor is move to the end of the buffer.
Deleting Text
There are several commands to delete text in Emacs. The basic deletion commands are C-d to delete the character at the cursor and del (rubout or backspace) to delete the character before the cursor. Again these are frequently mapped to the modern keyboard keys delete and backspace respectively. C-k (kill) deletes to the end of line, but does not delete the newline unless that is the only character to be deleted. To delete an entire non-blank line use the following keystrokes, C-a C-k C-k, which move to the beginning of the line (C-a), deletes up to the newline (first C-k), and finally deletes the newline (second C-k).
At times you may want to delete a region of text, other editor application may call regions selected text. To create a region you must first create a mark. Regions in Emacs are defined relative to a mark and the cursor. To create a mark use the keystroke command C-Space or C-@. Then to create a region simply use the cursor navigation commands to define your region. In some versions of Emacs the region may not be highlighted. If this is the case and you wish to identify the start and end of your region, you can use the command C-x C-x, which swaps the mark and the cursor. This may also sometimes be used as a method of moving around in the buffer. Once a region is defined you can kill (delete) it by issuing the C-w command. For example if you wanted to delete the current sentence, you could issue the following command sequence, M-a C-Space M-e C-w.
Undo
At times you will want to correct a mistake, or copy text to a location other than where you deleted it from. The commands C-x u and C-_ will issue a single undo command. By repeatedly issuing either command you may undo multiple operations including insertions and deletions among others. Some versions Emacs limit the number of undo operations allowed.
The Kill Ring
Each time you delete text, through any of the methods described above, the text is inserted into the kill ring. To retrieve the text from the kill ring, position you cursor where you wish the text to be inserted and issue the C-y (yank) command. Repeated use of C-y will insert the text more times. Alternatively you may wish to copy text into the kill ring without deleting it from the buffer; use M-w to achieve this function.
In summary, C-w, M-w and C-y are similar to Cut, Copy and Paste in other applications respectively, however there are some important differences that will be covered in later articles.
Next in this series: Part 3 – Buffers and Windows
Until next time.
-3Monkeys
Popularity: 26% [?]