Emacs series tutorials (1): basic usage
Learning Emacs series tutorial (2): navigation
The last time I talked about how to move the cursor in Emacs, this will introduce how to edit text in Emacs.
The core function of any text editing software is to edit text, and Emacs is no exception. Although it also has many other powerful skills, it is inseparable from text editing. In terms of text editing, that is, typing. Specifically, we need to implement a WYSIWYG input method. There is no difference between typing in Emacs and notepad. In the same way, you can open a file and directly type characters in it. This is a big difference from Vim. We also need to know the mode in which we are working. Otherwise, we will not be able to respond to the screen when making a random knock.
1. File Operations
as we mentioned earlier, editing text is to open a file and type characters in it. Therefore, the first thing we do is to open a file.
C-x C-F after entering this command, you will see a prompt" find file: "In the echo area :", next is the path of my document. enter the name of the file you edited. Note that the input file name can contain a path, such as D: \ text.txt or a relative path. In Windows, we can also use the windows-style Backslash "\". Of course, we can also use the forward slash "/". If a new path is entered, the current path of Emacs will jump to the place you entered (a new buffer is actually created ). If Emacs does not find the file you entered, it will automatically create a new file with the name you entered. In addition, emacs supports drag and drop, which means you can drag the file icon to Emacs to open it.
when you accidentally open a file, you can use C-x C-v to change one, the operation is the same as that of C-x C-f, the difference is that Emacs processes some differences in buffer.
C-x C-S this command is used to save files. another command is C-x C-W , both of which are relatively simple.
II. Input text
In addition to some basic input methods, emacs can also enter non-printable characters, that is, those before the ASCII table.
use C-Q (N). N represents an eight-digit number, then, the symbols in the ASCII table corresponding to N can be printed.
Unicode characters such as Japanese, Korean, and C-x 8 is followed by the name or encoding of the characters in the Unicode standard to output this mess. I believe there will be no such long string of numbers, and we have more advanced solutions (advertising time .. When .. Now, we are introducing the Unicode Character super input tool-sogou soft keyboard, which saves you the trouble of remembering a lot of hexadecimal numbers and Inputting Chinese characters. It is really a must-have for home travel.
3. delete text
compared with input, emacs deletes more text.
backspace, backspace, which is more traditional.
the Del key removes the character at the cursor. Although this is common, it violates the Emacs principle: "You do not need to leave the primary key area ", therefore, we use c-d instead.
M-D , this is used to delete a word (remember the word in the Chinese text to represent the sentence in two adjacent punctuation marks, so if you are playing the Chinese key or less useful, I will not see a long sentence ). It also deletes the cursor from the current position to the end of the word and leaves the First Half of the word to you.
correspondingly, the first half of a word can be deleted. M-backspace.
M-k , delete a sentence, which is different in Chinese and English. In Chinese, it will only be deleted until the end, including the end. In English, it does not recognize '.','! ', But the entire segment is deleted (two carriage returns are used for English segments ). Like M-D, it is also deleted from the cursor. C-x backspace.
c-k , Delete the current row from the cursor.
for a detailed example, see: (the text covered by a wide line is deleted using the command pointed by an arrow. Note the differences between Chinese and English.)
4. Undo commands
operations may fail. In Windows, the frequency of using Ctrl + z commands is quite high, however, pressing CTRL + Z in Emacs will find that the window is minimized. C-/ is used in Emacs to achieve the Undo effect. You can also use C-_ or C-x u , all three correspond to the undo command.
similar to VIM, the deleted content in Emacs is also saved in a buffer, which is equivalent to a clipboard. We can conveniently call out something that is put in at a time, I haven't taken a closer look at this place. I will talk about it later.
the preceding section describes how to undo operations on text. There is also a commonly used command C-G , this command is used to undo the command. You can use it if you lose half of the command and find it is incorrect.
V. Miscellaneous commands
Some of the more fragmented commands are commonly used. Well, we should put them in the first chapter. Let's put them here first.
HELP command:
C-h tCall up Emacs tutorial.
C-HRCall up Emacs manual.
C-h k (command)Call up the corresponding Command help. For example, C-h k c-N is to view the help of C-n.
Blank line:
Insert empty rows,C-o. Delete empty rowsC-X c-oNote: if there are many blank lines, this command will delete only one blank line, and only one will be deleted directly. These two commands are not exactly the same. inserting a blank line is actually inserting a carriage return line break, but the criteria for deleting a blank line is that this line does not delete any text, if we press C-O in the middle of a line of text, the content behind the cursor will move to the next line, and then press C-X c-o, but there is no response, because there is content in front of this line.
Repeated commands:
The previous chapter describes the repeated commands for two numeric parameters. Here is another example without numeric parameters.C-x ZThe object of this command is the command that was previously input. For example, if you press C-N first and then press C-x Z, the C-N will be repeated once, then, every time we press Z, we will go down one line, which is quite convenient.
Summary:
Buttons |
Command |
Function |
C-x C-F |
Find-File |
Open a file |
C-x C-V |
Find-alternate-File |
Open another file |
C-x C-S |
Save-Buffer |
Save files |
C-x C-W |
Write-File |
Save another file |
C-Q (N) |
Quoted-insert |
Insert characters. N indicates the octal ASCII code of the characters. |
C-x 8 |
Ucs-insert |
Insert Unicode characters |
C-d |
Delete-Char |
Delete the character at the cursor |
Backspace |
Delete-backward-Char |
Delete the character before the cursor |
M-d |
Kill-word |
Delete a word from the cursor |
M-backspace |
Backward-kill-word |
Delete the word before the cursor |
C-k |
Kill-line |
Delete the current row starting with the cursor |
M-K |
Kill-sentence |
Delete a sentence starting with the cursor |
C-x backspace |
Backward-kill-sentence |
Delete the sentence before the cursor |
(None) |
Kill-paragraph |
Delete a paragraph starting with the cursor |
(None) |
Backward-kill-paragraph |
Delete the paragraph before the cursor |
C -/
|
Undo |
Undo |
C -_ |
Undo |
Undo |
C-x u |
Undo |
Undo |
C-G |
Keyboard-quit |
Undo command |
C-h t |
Help-with-tutorial |
Call up Emacs tutorial |
C-h r |
Info-emacs-Manual |
Call up Emacs manual |
C-h k (command) |
Describe-Key |
View the corresponding Command help |
C-o |
Open-line |
Insert empty rows |
C-X c-o |
Delete-blank-line |
Delete empty rows |
C-x Z |
Repeat |
Repeat the previous command |
Not complete...