Use Emacs on my Arch + Awesome

Installation

Firstly, I installed Emacs with the command:

pacman -S Emacs

and then [pacman] said to download these package, input Y + Enter, then Emacs will be installed.

resolving dependencies...
looking for inter-conflicts...

Packages (4): libotf-0.9.13-1  m17n-db-1.6.4-1  m17n-lib-1.6.4-2  Emacs-24.3-4

Total Download Size:    35.59 MiB
Total Installed Size:   97.96 MiB

:: Proceed with installation? [Y/n] 

After having Emacs installed, I tried to run it and it comes out like that:

In Emacs’s tutorial the first command to bear in mind is:

C-x C-c

which exit the Emacs window or execution in terminal.

Cursor movements

Next, I think it’s important to know how to move around in the text. There are three shortcut for the basic movings.

C-L: next half screen
C-V: next full screen
M-V: previous full screen

where the C is Ctrl key and M refers to Alt or ESC key.
Next is the cursor movements, usually moved by arrows: up, down, left, right, but it is not an efficient way to move by changing my hands position a lot. So, in Emacs the movement can be done with:

C-P: previous line
C-N: next line
C-B: backward
C-F: forward

Just try it several times, then you will see that with left hand pressing Ctrl, you can perform an previous or next line movement, and with your right hand pressing Ctrl, you can perform an backward or forward movement.
C-F and C-B do one character movement, and we can also use M-F and M-B to perform an word based movement.

M-F: forward next word
M-B: backward previous word

Em..that’s cool! Although I am not familiar with them now, yet I can see the high efficiency type on keyboard in the future.
Jumping to the beginning or ending of one line or one sentence will be useful for fast navigation in the text. Emacs
offers two ways to directly reach the two point by key binding:

C-A: line beginning
C-E: line end
M-A: sentence beginning
M-E: sentence end

After testing these key bindings, I found that maybe I can M-A and M-E for fast page navigation. That will be test in the future. There are also two shortcuts to reach the head and the end of the whole text file:

M-<: to the head
M->: to the end

So far, there comes all the navigation operations, during the testing two other functions are useful for me, one is the undo command C-x U, the other is the quit command C-g.

Inserting and deleting

Also, there are some commands for windows control but now I did not encounter any of that case. So I escaped that section and continued exploring the inserting and deleting part. For inserting any text, just type them from you normal keyboard and the referred character can be input, such as a b c d , . \ ? ! A B C D*. For deleting, the two normal mode with backspace and delete can act same with other editors. But in Emacs, \<DEL> refer to backspace key which is not common for remember, so I still use backspace to mark it. The following codes list the main kinds of deletings:

backspace: as you know delete the character before the cursor
C-D: same as the delete key does deleting the character after the cursor
M-backspace: kill the word before the cursor
M-D: kill the word after the cursor
C-K: kill all the content to the end of the current line
M-K: kill all the content to the end of the current sentence

Why using the word kill? That will be explained in the following yanking part. Now I focused on the deleting operations. To delete a region, Emacs lets us mark two points to form a text region, then just typing C-W, the region will be killed. To mark a point, just move your cursor to the exact point you’d like and type C-Spacebar. Give it a try!
It’s time to deal with the yanking, all the killed buffer can be yanked back to anywhere the cursor located by typing C-Y.

C-Y: the exact action of paste other platforms

rest for a while :D


Suddenly, I recognized that I didn’t know how to save the changes in Emacs, then I googled it:

C-x C-S: save the current buffer

File operations

Ok, let’s go on to explore the great Emacs (editor or OS?)
Using C-Y, any currently killed buffer can be yanked. Then the problem came how can I yank the previous killed buffers, Emacs offers another shortcut for this M-Y, by pressing this key binding, an iteration will be performed in all the killed buffers, that’s to say the previous buffers will be yanked by the inversed sequence.
Bomb! An convenient key binding for UNDO is C-/, which is easier for pressing than C-x U.
Next, I’d like to learn something about the file operation.

  1. C-x C-f: find a file which is actually the open file command, you agree? That is to say I can type a file name in the minibuffer to open it.
  2. C-x C-s: save a file as described above this is useful before finally exit.
  3. C-x C-w: save as another file.

A good day for reading :)

Buffers

Ok, buffers for Emacs are the files opened scince starting Emacs, usually opened by the command C-x C-f, remember that? Each buffer saves the changes of the related file. I care much about how to save them, as mentioned above save the current buffer I can press C-x C-s, and save the all of the loaded buffers I can press C-x s. Then, I need to know how many or what buffers I opened, just press C-x C-b and a new window will show up listing the buffers you loaded. Now I want to return to the main window and close the new buffers shown windown, just press C-x 1. Awesome! If there are several buffers, input C-x b and I can input the buffer name in the minibuffer area to change to it.
Let’s see what does the command C-x mean, x refers to eXtend which means C-x can extend a normal charactor to behave a specific command, such as C-x u for undo and C-x s for saving all.
By the way, the meaning of M-x is eXtend the string command, which let the users can input a string command. For example, M-x replace-string, which can be input by typing : M-x repl + <Tab> + s + <Tab>. \<Tab> will automatically complete the related input. Another example of M-x is M-x recover-file which can recover a file from its auto-saved files.

Searching and replacing

Searching and replacing are the necessary functions for any editor, Emacs do that elegantly. But it should be known that the searching in Emacs is incremental, that it to say as you input a character Emacs searches the whole buffer in real-time. The searching command goes here:

C-s: forward searching
C-r: backward searching

Finding and replacing is not explained by Emacs’s basic tutorial, while I googled it and list the commands below:

M-Shift 5: M-%, in command mode M-x query-replace

This searches forward and you want to replace the found string press y, n to skip and ! to do all remaining matched cases. If you want to quit, just press q. The replacing operation is interactive, you need to confirm each replacement. If you want to do a replacement to all once in a time. M-x replace-string can do that, but be careful to use that.

Windows

In Emacs, we need to open another document as reference, so multiple windows are useful. To add a new window, just press C-x 2 or C-x 3 which will seperated the current window into two by horizontally and vertically. The two windows show the same content as seperated, but usually we want the second window show another document. We can move the focus between windows by pressing C-x o. And in each window all the Emacs commands can be executed, of course, openning a new file by C-x C-f. But for easier operation, there is an alternative way to open a new document in a seperated window: C-x 4 C-f, namely, there are 4 ways to seperate the current windows. Finally, C-x 1 will keep the focused window and kill all the other windows. For the second windows usually act as a reference, so I don’t want to change focus to the reference, but I need to scroll it for more information. Then just typing C-M v brings you there. woW…woW…


Conclusion

That is all for my first signt on Emacs within two days. I feeled that an only word can be used to describe it.
Magic!